所以我有这个自动电子邮件脚本,一切正常,但我遇到的问题是,当弹出一封无效的电子邮件时,它会出错并退出,我想知道的是,有没有办法告诉它如果有错误跳过该记录并移动到下一个?
Set objMessage = CreateObject("CDO.Message")
Set app = CreateObject("Excel.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
For Each f In fso.GetFolder("##############").Files
If LCase(fso.GetExtensionName(f)) = "xls" Then
Set wb = app.Workbooks.Open(f.Path)
set sh = wb.Sheets("Auto Email Script")
row = 4
email = sh.Range("A" & row)
LastRow = sh.UsedRange.Rows.Count
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim f
Set f = fso.OpenTextFile("#####################.txt", ForReading)
BodyText = f.ReadAll
For r = row to LastRow
If App.WorkSheetFunction.CountA(sh.Rows(r)) <> 0 Then
email = sh.Range("A" & row)
sh.Range("I" & row).Value = "Sent"
row = row + 1
End if
If email = "" Then
Wscript.Quit
End if
objMessage.Subject = "Billing: Meter Read"
objMessage.From = "################"
objMessage.To = email
objMessage.TextBody = BodyText
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "################"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
objMessage.Send
Next
wb.Save
f.Close
Set f = Nothing
Set fso = Nothing
wb.Close
End If
Next