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

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -