I am trying to save an Excel sheet as a pdf and then send as an email attachment but it keeps failing at the section:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= path + filename, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
I get the attached error
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= path + filename, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
I get the attached error
Code:
Sub Saveaspdfandsend()
Dim edress As String
Dim subj As String
Dim message As String
Dim filename As String
Dim outlookapp As Object
Dim outlookmailitem As Object
Dim myAttachments As Object
Dim path As String
Dim attachment As String
Set outlookapp = CreateObject("Outlook.Application")
Set outlookmailitem = outlookapp.createitem(0)
Set myAttachments = outlookmailitem.Attachments
path = Environ$("userprofile") & "OneDrive - D WRIGHT CONSULTING LIMITED\DWC WIP\Worksheets\"
Application.DisplayAlerts = False
filename = "Worksheet for period" & Format(Date, "dd mm yyyy") & ".pdf"
subj = Sheet1.Cells(3, 5)
[COLOR=rgb(0, 0, 0)]ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= path + filename, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False[/COLOR]
attachment = path + filename
outlookmailitem.To = ""
outlookmailitem.cc = ""
outlookmailitem.bcc = ""
outlookmailitem.Subject = filename
outlookmailitem.body = "Please find attached weekly Service sheet"
myAttachments.Add (attachment)
outlookmailitem.display
outlookmailitem.send
Application.DisplayAlerts = True
Set outlookapp = Nothing
Set outlookmailitem = Nothing
End Sub
[code/]
[ATTACH type="full" width="370px"]57963[/ATTACH]
Any help gratefully received