对象要求将文件附加到电子邮件的错误
我目前正在尝试在excel vba中开发一个macros来发送附加到电子邮件中的选定范围。 由于我对vba的知识是零,我一直在浏览互联网,并能够把这个脚本放在一起。 目前,我正在尝试附加文件时,所需的对象的错误。
感谢你们给我的每一个帮助和反馈。
Sub AttachActiveSheetPDF() Dim IsCreated As Boolean Dim i As Long Dim PdfFile As String, Title As String Dim OutlApp As Object PdfFile = ActiveWorkbook.FullName i = InStrRev(PdfFile, ".") If i > 1 Then PdfFile = Left(PdfFile, i - 1) PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf" With ActiveSheet.PageSetup .Orientation = xlPortrait .PrintArea = "$A$1:$P$84" .Zoom = False .FitToPagesTall = False .FitToPagesWide = 1 End With With ActiveSheet .ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False End With On Error Resume Next Set OutlApp = GetObject(, "Outlook.Application") If Err Then Set OutlApp = CreateObject("Outlook.Application") IsCreated = True End If OutlApp.Visible = True On Error GoTo 0 Dim Ebody As String Ebody = "<p>Buenas Dias,</p> <p>Adjunto es el documento.</p>" With OutlApp.CreateItem(0) .Subject = Quotation_de_Aerolinea .To = "..." .CC = "..." .HTMLBody = Ebody myAttachments.Add (PdfFile) On Error Resume Next .Display Application.Visible = True If Err Then MsgBox "E-mail was not sent", vbExclamation Else MsgBox "E-mail successfully sent", vbInformation End If On Error GoTo 0 End With End Sub
提前致谢
myAttachments
不是Outlook中的集合,看起来像可能来自其他代码。
尝试:
.Attachments.Add PdfFile