vba - Can't send multiple Outlook Messages -


i can send single outlook message using excel vba. however, want loop through rows , send email each row meets condition.

unfortunately, when put email code in loop 1 email gets sent or none @ (depending on how structure code).

is there calling outlook multiple times should know?

private sub commandbutton1_click()     dim outapp object     dim outmail object     dim myvalue variant     dim contactrange range     dim cell range     dim toaddy string, nextaddy string     dim integer      set contactrange = me.range("contactyesno")      myvalue = inputbox("enter body of email message.")      each cell in contactrange          if range(cells(cell.row, cell.column).address).value = "yes"             nextaddy = range(cells(cell.row, cell.column).address).offset(0, 5).value              toaddy = nextaddy & ", " & toaddy          end if      next cell      if len(toaddy) > 0          toaddy = left(toaddy, len(toaddy) - 2)      end if  = 0 1 'short loop testing purposes      set outapp = createobject("outlook.application")     set outmail = outapp.createitem(0)      outmail          .to = toaddy          .cc = ""         .bcc = ""         .subject = "test email"         .body = myvalue         .send     end      set outmail = nothing     set outapp = nothing  next   end sub  

take createobject line out of loop:

set outapp = createobject("outlook.application") = 0 1 'short loop testing purposes     set outmail = outapp.createitem(0)     ... 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -