vba - If error then skip sending an email -


i have piece of code sends me email when button pressed. if reason email won't send don't want code break, ignore command , carry on. how add current code?

dim outapp object dim outmail object dim strbody string  set outapp = createobject("outlook.application") set outmail = outapp.createitem(0)  strbody = thisworkbook.name & vbnewline & _           environ("username") on error resume next outmail     .to = "bm@email.co.uk"     .cc = ""     .bcc = ""     .subject = "ogi statements used"     .body = strbody     .send end on error goto 0 set outmail = nothing set outapp = nothing 

thank you

you change error statement avoid .send method in case of earlier error - if error occurs actual sending of email there's not lot can execution has been handed on application , it's out of error handler's scope speak.

see if of use:

on error goto skip: outmail     .to = "bm@email.co.uk"     .cc = ""     .bcc = ""     .subject = "ogi statements used"     .body = strbody     .send end skip: on error goto 0 set outmail = nothing set outapp = nothing 

Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -