【发布时间】:2017-05-29 00:25:20
【问题描述】:
我正在尝试使用 Outlook 向 Excel 工作表中column:A 中的每个电子邮件地址发送电子邮件,并在正文中插入一个 Word 文档。我编写了以下代码,但它给了我运行时错误 91。我使用的是 Office 2013。
Public Sub Create_Outlook_Email()
Dim OutApp As Object, OutMail As Object, OutWordEditor As Object
Dim WordDoc As Object
Dim wordfile As String
Dim rng As Range
Dim row As Range
Dim cell As Range
'Create new Outlook email
Set rng = Range("a2:a50")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set OutWordEditor = OutMail.GetInspector.WordEditor
For Each row In rng.Rows
For Each cell In row.Cells
With OutMail
.To = cell.Value
.Subject = "Your emails are moving on " & Range("e2").Value & "- don't get left behind "
wordfile = Application.GetOpenFilename(Title:="Select MS Word file", MultiSelect:=False)
Set WordDoc = GetObject(wordfile)
WordDoc.Content.Copy
WordDoc.Close
OutWordEditor.Content.Paste
'See if Outlook is using Word to edit messages
.display
.send
End With
Set OutApp = Nothing
Set OutMail = Nothing
Set OutWordEditor = Nothing
Set WordDoc = Nothing
Next cell
Next row
End Sub
【问题讨论】:
标签: excel vba outlook ms-word runtime-error