【发布时间】:2018-07-24 08:34:44
【问题描述】:
我有以下代码,但它不工作。我对 VBA 也很陌生。该代码可用于填充电子邮件模板,但只要我添加 .Attachment.Add 它就不起作用。
Sub CreateMail()
Dim objOutlook As Object
Dim objMail As Object
Dim rngTo As Range
Dim rngSubject As Range
Dim rngBody As Range
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)
With ActiveSheet
Set rngTo = .Range("E2")
Set rngSubject = .Range("E3")
Set rngBody = .Range("E4")
.Attachments.Add "Z:\PHS 340B\Letters of Non-Compliance\..Resources\W9 Form\VPNA W-9 01 09 2017"
End With
With objMail
.to = rngTo.Value
.Subject = rngSubject.Value
.Body = rngBody.Value
.Display 'Instead of .Display, you can use .Send to send the email _
or .Save to save a copy in the drafts folder
End With
Set objOutlook = Nothing
Set objMail = Nothing
Set rngTo = Nothing
Set rngSubject = Nothing
Set rngBody = Nothing
End Sub
【问题讨论】:
-
你确定路径正确吗?
-
是的,我直接从共享网络驱动器复制了它
-
错误提示“对象不支持此属性或方法”
标签: excel vba outlook attachment