创建的代码可将活动表导出为pdf,并将动态范围作为文件名保存到特定的中央目录(需要将此创建的pdf文件附加到Outlook电子邮件)。一切正常,除非未保存已保存的pdf
Private Sub cbSubmitRFC_Click()
'Submit RFC button coding, send worksheet(RFC) as pdf attachment to Credit Mailbox
Dim xOutApp As Object
Dim xOutMail As Object
Dim xActiveSheet As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Body content" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
ChDir "M:\Credits 2019\Submitted RFC's"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"M:\Credits 2019\Submitted RFC's\" & Range("I8").Value & " " & "CN" & Range("E14").Value & " " & "Inv" & Range("H11") & ".pdf"
With xOutMail
.To = "LS_CreditRequests@general.com"
.CC = ""
.BCC = ""
.Subject = "RFC" & " " & Range("I8") & " " & "Acc No." & Range("E8") & " " & "CN" & Range("E14") & " " & "Inv No." & Range("H11")
.Attachments.Add
.Attachments.Save
.Display
End With
MsgBox ("RFC Successfully Submitted")
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
我怀疑以下部分是问题,但不知道如何正确编码以附加新保存的pdf。以前的代码如下(它以excel格式创建附件“ ActiveWorkbook”,而不是保存的pdf)
.Attachments.Add (ActiveWorkbook.FullName)