I'm getting a run time error (see attached) for the code below. It works on my computer...but when others try to use this function they get the error. Not sure what the path and file name its referring to or why this would come up. Any help is appreciated. Thanks!
Sub AttachPSRSheetPDF()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object
' Define PDF filename
PdfFile = ActiveWorkbook.FullName
i = InStrRev(PdfFile, "PROJECT STATUS REPORT")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = "PROJECT STATUS REPORT" & ".pdf"
' Export activesheet as PDF
Worksheets("PROJECT STATUS").Range("B7:O65").ExportAsFixedFormat _
Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
' 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 = "Contracts - SOV - Budgets"
.To = "email@email.com" ' <-- Put email of 'copy to' recipient here
.Body = "Hi," & vbLf & vbLf _
.Attachments.Add PdfFile
' Try to send
On Error Resume Next
.Display
Application.Visible = True
If Err Then
MsgBox "E-MAIL WAS NOT CREATED", vbExclamation
End If
On Error GoTo 0
End With
End Sub
Bookmarks