【发布时间】:2020-09-06 11:59:26
【问题描述】:
我正在尝试将驱动器位置内的 pdf 文件附加到邮件中。我认为这是我在命名范围中缺少的基本内容。
代码在.Attachments.Add 行中中断。
Sub Mail()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim mainfont As String
Dim headerfont As String
Dim subheaderfont As String
Dim closemain As String
Dim closeheader As String
Dim closesubheader As String
Dim Ash As Worksheet
Set Ash = ActiveSheet
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutMail = OutApp.CreateItem(0)
'construct email
With OutMail
.To = Range("To").Value
.cc = Range("Cc").Value
.Subject = Range("Subject").Value
.Attachments.Add ("FilePathYTD.pdf")
.Display
End With
End Sub
【问题讨论】:
-
“
.Attachments.Add行中的代码中断” - 它是否给出任何具体的错误消息? -
错误代码状态验证路径和文件名是否正确
标签: excel vba pdf outlook attachment