【发布时间】:2020-06-23 15:36:53
【问题描述】:
我正在尝试从 Outlook vba 向多个收件人发送邮件。
收件人邮件地址取自excel表格的A列。当我运行以下代码时,出现错误“运行时错误 1004;方法‘对象单元格’_Global’失败”
如何将同一封邮件同时发送给多个收件人。
收件人:Abc@gmail.Com; bhy@gmail.com; rft@gmail.com 抄送:hjuy@gmail.com; ijk@gmail.com 主题:测试邮件
Code:
Sub Sendmail()
Dim olItem As Outlook.MailItem
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSht As Excel.Worksheet
Dim sPath As String
Dim iRow As Long
iRow = 1
sPath = "XX"
' // Excel
Set xlApp = CreateObject("Excel.Application")
' // Workbook
Set xlBook = xlApp.Workbooks.Open(sPath)
' // Sheet
Set xlSht = xlBook.Sheets("Sheet1")
Do Until IsEmpty(Cells(iRow, 1))
Recip = Cells(iRow, 1).Value
' subject = Cells(iRow, 2).Value
' Atmt = Cells(iRow, 3).Value '
' // Create e-mail Item
Set olItem = Application.CreateItem(olMailItem)
With olItem
Set olRecip = .Recipients.Add(Recip)
.CC = xlSht.Range("B1")
.subject = "test"
.Display
.Send
End With
' // Close
xlBook.Close SaveChanges:=True
' // Quit
xlApp.Quit
'// CleanUp
iRow = iRow + 1
Loop
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSht = Nothing
Set olItem = Nothing
End Sub
【问题讨论】:
-
你在哪个办公室/窗口运行?
-
Windows 8.1 桌面