Hi! I am having trouble with saving a range as PDF and mail it right after. It works sometimes and sometimes it does not. I am not sure what the issue is. Also on a side note I cannot save those file in subfolders on my desktop even if I change the paths. Does anyone have an idea why it works sometimes and not consistently?
VBA Code:
Sub SaveAsPDF()
'Create and assign variables
Dim saveLocation As String
Dim rng As Range
saveLocation = "C:\Users\Username\Desktop\"
Set rng = Sheets("SheetName").Range("G1:S46")
'Save a range as PDF
rng.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Worksheets(6).Range("U1").Value & ".pdf"
'Create Outlook email
Set xOutlookObj = CreateObject("Outlook.Application")
Set xEmailObj = xOutlookObj.CreateItem(0)
With xEmailObj
.Display
.To = ""
.CC = ""
.Subject = Range("U1").Value & ".pdf"
[COLOR=rgb(209, 72, 65)] .Attachments.Add "C:\Users\UserName\Desktop\" & Worksheets(6).Range("U1").Value & ".pdf"[/COLOR]
If DisplayEmail = False Then
'.Send
Range("Q2") = Range("Q2") + 1
End If
End With
Exit Sub
End Sub