我有一张名为“测试”的表格,其中 A 列是电子邮件地址列表。
我想向所有地址发送电子邮件。
Sub EmailSend()
Dim objOutlook As Object
Dim objMail As Object
Dim i As Integer
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
For i = 1 To 10
With objMail
.to = Sheets("Test").Range("A" & i).Value
.Subject = "hi"
.body = _
"Hi " & Sheets("Test").Range("B" & i) & Sheets("links").Range("G" & 1)
.send
End With
Next i
End Sub
宏向 A1 中的地址发送电子邮件,然后出现错误element was moved or deleted.
出现在行中
.to = Sheets("Test").Range("A" & i).Value
最佳答案
我猜您尝试发送的第二行可能有错误。因此,使用下面的代码并检查它在立即窗口中显示的内容。
更新:
我添加了 CreateItem
For
中的行循环并为每封邮件重置它。可能是错误消息提示的邮件项目。
Sub EmailSend()
Dim objOutlook As Object
Dim objMail As Object
Dim i As Integer
Set objOutlook = CreateObject("Outlook.Application")
For i = 1 To 10
Set objMail = objOutlook.CreateItem(0)
With objMail
Debug.Print Sheets("Test").Range("A" & i).Value
.to = Sheets("Test").Range("A" & i).Value
.Subject = "hi"
.body = _
"Hi " & Sheets("Test").Range("B" & i) & Sheets("links").Range("G" & 1)
.display
'.send
End With
Set objMail = Nothing
Next i
End Sub
关于excel - 使用工作表列中的地址发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56666083/