【发布时间】:2018-10-31 22:00:17
【问题描述】:
我的代码没有找到要附加到电子邮件的导出文件。
我确定我在 myattachments.add 行中做错了什么。
每个客户端的文件名和文件目录总是不同的,这就是为什么我在每个引用中专门为文件名指定了一个单元格。
我要将此 Excel 文件复制到每个客户端文件夹并从那里运行代码。
Sub sendremindermail()
ChDir ThisWorkbook.Path & "\"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("'Costing'!C1"), Openafterpublish:=True
Dim outlookapp As Object
Dim outlookmailitem As Object
Dim myattachments As Object
Set outlookapp = CreateObject("outlook.application")
Set outlookmailitem = outlookapp.createitem(0)
Set myattachments = outlookmailitem.Attachments
With outlookmailitem
.To = Range("'Costing'!C8")
myattachments.Add ThisWorkbook.Path & Range("'Costing'!C1") & ".pdf" ' it cant find the pdf in the same directory
'.send
.Display
End With
Set outlookmailitem = Nothing
Set outlookapp = Nothing
End Sub
我是 VBA for Excel 的新手。
【问题讨论】:
标签: excel vba pdf outlook attachment