excel vba - VBA - Loop, Catch error, assign variable and continue looping? -


i have email automation program. want create error catch recpname. when recpname passed lotus notes , returns error (due spelling errors), want capture error catch.

i still want loop keep going , continue down list, tell user names couldn't send emails to.

here's code:

sub send_html_email()      const enc_identity_8bit = 1729      'send lotus notes email containing links files on local computer      dim nsession object      'notessession     dim ndatabase object     'notesdatabase     dim nstream object       'notesstream     dim ndoc object          'notesdocument     dim nmimebody object     'notesmimeentity     dim sendto string     dim subject string     dim html string, htmlbody string     dim wb workbook     dim ws worksheet     dim lstrow long, j long     dim recpname string, candiname string     dim hyperlink      set wb = thisworkbook     set ws = wb.worksheets("detail")      ' instantiate lotus notes com's objects.      lstrow = ws.range("b" & rows.count).end(xlup).row     set nsession = createobject("notes.notessession")       'using lotus notes automation classes (ole)     set ndatabase = nsession.getdatabase("", "")      if not ndatabase.isopen ndatabase.openmail      j = 3 lstrow         recpname = ws.cells(j, 2).text         candiname = ws.cells(j, 1).text          sendto = recpname         subject = wb.worksheets("email settings").range("b1").text         debug.print subject          set nstream = nsession.createstream          htmlbody = "<p>" & "hi " & ws.cells(j, 2).text & "," & "</p>" & _         vbcrlf & _         "<p>" & sheets("email settings").cells(2, 2).text & vbcrlf & _         sheets("detail").cells(j, 1).text & "</p>" & vbcrlf & _         "<p>" & sheets("email settings").cells(3, 2).text & _         "<br>" & sheets("email settings").cells(4, 2).text & _         "<br>" & sheets("email settings").cells(5, 2).text & _         "<br>" & sheets("email settings").cells(6, 2).text & "</p>" & _         "<p>" & sheets("email settings").cells(9, 2).text & _         "<br>" & sheets("email settings").cells(10, 2).text & _         "<br>" & sheets("email settings").cells(11, 2).text & _         "<br>" & sheets("email settings").cells(12, 2).text & _         "<br>" & sheets("email settings").cells(13, 2).text & _         "<br>" & sheets("email settings").cells(14, 2).text & _         "<br>" & sheets("email settings").cells(15, 2).text & "</p>"          html = "<html>" & vblf & _                "<head>" & vblf & _                "<meta http-equiv=""content-type"" content=""text/html; charset=utf-8""/>" & vblf & _                "</head>" & vblf & _                "<body>" & vblf & _                htmlbody & _                "</body>" & vblf & _                "</html>"          nsession.convertmime = false     'don't convert mime rich text          set ndoc = ndatabase.createdocument()          ndoc             .form = "memo"             .subject = subject             .sendto = split(sendto, ",")              set nmimebody = .createmimeentity             nstream.writetext html             nmimebody.setcontentfromtext nstream, "text/html; charset=utf-8", enc_identity_8bit              .send false             .save true, false, false         end          nsession.convertmime = true      'restore conversion      next j     set ndoc = nothing     set nsession = nothing     msgbox "the e-mail has been created , distributed", vbinformation  end sub 

maybe code can you:

sub send_html_email()      dim cnt_err integer: cnt_err = 1     on error goto errorhandler      const enc_identity_8bit = 1729      ' insert rest of code here      msgbox "the e-mail has been created , distributed", vbinformation      exit sub  errorhandler:     ' insert code handle error, e.g.     wb.worksheets("sheettosavemailsnotsent").range("a" & cnt) = recpname     cnt = cnt + 1             ' next instruction continue subroutine execution     resume next  end sub 

for more can go link.

hth ;)


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -