Hello all,
I was creating a VBA code to insert a PDF to an email.
I was able to do it basically, but once I changed up the file name & path to be dynamic, it could not find the PDF document via the new naming criteria. Below is my code.
I require assistance on the line with "myAttachments.Add File"
If anyone can give me assistance with the Syntax needed for this line to run with the dynamic name change, I would greatly appreciate it.
Thank you,
I was creating a VBA code to insert a PDF to an email.
I was able to do it basically, but once I changed up the file name & path to be dynamic, it could not find the PDF document via the new naming criteria. Below is my code.
Code:
Sub sendReminderMail()ChDir "C:\Users\rbs\Desktop"
Dim Path As String
Dim filename As String
Dim File As String
Path = "C:\Users\rbs\Desktop\Invoices\"
filename = Range("B1") & Range("C1") & " - " & Range("B9")
File = Path & filename
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:= _
File, OpenAfterPublish:=True
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachments As Object
Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments
With OutLookMailItem
.To = Range("B12")
.ReadReceiptRequested = True
.Subject = "Invoice #" & Range("C1") & " - " & Range("B9")
.Body = "Here is your invoice
myAttachments.Add File
'.Send
.Display
End With
Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
End Sub
I require assistance on the line with "myAttachments.Add File"
If anyone can give me assistance with the Syntax needed for this line to run with the dynamic name change, I would greatly appreciate it.
Thank you,