我正在尝试将保存为pdf的工作表附加为电子邮件中的附件。
我已经设法找出如何保存pdf,并且我知道如何将工作表保存为pdf,但我希望能够将pdf附加到电子邮件而不需要保存pdf的硬拷贝。这可能吗?
答案 0 :(得分:0)
随意使用我发现的代码,只需稍加修改即可轻松实现! :)
Private Sub GenerateEmail(TemplateFileName As String, AttachmentFilePath As String, tableRange As Range, subjectText As String, Optional AdditionalCC As String)
Application.ScreenUpdating = False
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
'''' This will use a pre-existing template, otherwise use commented out line below is and cut this line out
Set OutMail = OutApp.CreateItemFromTemplate(TemplateFileName)
'Set OutMail = OutApp.CreateItem(0)
With OutMail
'.Recipients.Add AdditionalCC
'.sendTo = sendToText
'.CC = sendCCText
'.BCC = sendBCCText
'.Subject = subjectText
'''' Use this for current Workbook (ONLY IF SAVED) ie. You'll need to create a function to save the Workbook first
'.Attachments.Add (ActiveWorkbook.FullName)
'''' Use this if you know the location for the saved Workbook
.Attachments.Add (AttachmentFilePath)
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
如果您想查看我从click here
获取此网站的网站