NVRensburg
Board Regular
- Joined
- Jul 1, 2014
- Messages
- 113
- Office Version
- 365
- 2016
- Platform
- Windows
Please can someone assist. When I run the below macro in my Excel 2016 it works perfectly. I've emailed the sheet to another colleague who runs Excel 2007, and when I try run it on her PC it gives me a runtime error 5 Invalud Proceudre Call or Argument. When I debug it highlights this line:
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
The full macro is:
Thanks for your help
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
The full macro is:
Code:
Sub EMAIL_AS_PDF()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object
' Not sure for what the Title is
Title = Range("$E$11")
' Define PDF filename
PdfFile = ActiveWorkbook.FullName
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf"
' Export activesheet as PDF
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
' Use already open Outlook if possible
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
' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)
' Prepare e-mail
.Subject = Range("$E$11")
.To = Range("$E$33")
.CC = "ushers@lantic.net" ' <-- Put email of 'copy to' recipient here
.Body = "Thank you for your recent purchase at Usher's Pool & Garden," & vbLf & vbLf _
& "To our valued Customer " & vbLf _
& "Please find attached a thank you letter regarding your recent purchase at Usher's Pool & Garden." & vbLf & vbLf _
& " " & vbLf _
& "Should you have any queries, please do not hesitate to contact us." & vbLf _
& " " & vbLf _
& "Kind Regards," & vbLf _
& " " & vbLf _
& "Usher's Pool & Garden Centre" & vbLf _
& " " & vbLf & vbLf
.Attachments.Add PdfFile
' Try to send
On Error Resume Next
.Send
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
' Delete PDF file
Kill PdfFile
' Quit Outlook if it was created by this code
If IsCreated Then OutlApp.Quit
' Release the memory of object variable
Set OutlApp = Nothing
End Sub
Thanks for your help
Last edited by a moderator: