Hello.
I've tried to make an macro which will send an email with an attached PDF from my spreadsheet.
So far so good I've managed to make it work, but for some reason it will now crash and give the highlighted error on .Attachments.Add Fname, where it tells me that the path doesn't exist or wasn't found. The only problem is, that the exact same macro just created that PDF, but in the same macro it tells me it doesn't find the path.
If I remove the Attachments.Add Fname the macro manage to send the email correctly just without my PDF.
In VBa it looks like this:
Sub SendWekomFileAsPDF()
' SendWekomFileAsPDF() Makro
ActiveSheet.Unprotect
Dim OutlookApp As Outlook.Application
Dim emItem As Object
Dim Recipient As String
Dim Subject As String
Dim Message As String
Dim Fname As String
' Message details
Recipient = Range("AA1") & ";" & Range("AA2") & ";" & Range("AA3")
Subject = Range("P7") & " - " & Range("G15") & " " & Range("O15") & " - Wekom"
Message = "Se venligst vedhæftede fil" & vbNewLine & vbNewLine & "Goods Receiving department"
Fname = Range("P7") & " - " & Range("G15") & " - " & Range("O15") & " - " & Range("U43") & ".pdf"
' Create PDF Attachment
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=Fname
' Create Outlook object
Set OutlookApp = New Outlook.Application
' Create Email Item, Display or send it
Set emItem = OutlookApp.CreateItem(olMailItem)
With emItem
.To = Recipient
.CC = Range("AC1") & ";" & Range("AC2") & ";" & Range("AC3")
.Subject = Subject
.body = Message
.Attachments.Add Fname '(This is where I get my error message - The path where it will safe the PDF is on Onedrive, I've tried to change it - But it won't work in any way for me)
'.Display
.send
End With
Set OutlookApp = Nothing
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Hope that anyone can help me out here.
Daniel
Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
Bookmarks