VBScript SMTP Auto Email

会有一股神秘感。 提交于 2019-12-04 22:52:36
row = 2
email = sh.Range("A" & row)
...
For r = row to LastRow
  ...
  objMessage.To = email
  ...
Next

You set email to the value of the cell "A2" and never change it. If you want to send a mail to multiple recipients, you should make that

objMessage.To = sh.Range("A" & r).Value

or (better) build a recipient list (assuming that your used range starts with headers in the first table row):

ReDim recipients(LastRow - row)
For r = row To LastRow
  recipients(r - row) = sh.Range("A" & r).Value
Next
objMessage.To = Join(recipients, ";")

and send the message just once. The MTA will handle the rest.


Side note: as Vishnu Prasad Kallummel pointed out in the comments your code doesn't close the Excel instance it started. Unlike other objects created in VBScript, Office applications won't automatically terminate with the script, so you have to handle it yourself:

...
wb.Close
app.Quit
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!