Help with send email from excel file and delete PDF after email has been sent

austie

New Member
Joined
May 29, 2018
Messages
14
Hi all,

I'm trying to get an excel file to save as pdf to a specific location
after which I want it to open up outlook and email a message to a predefine location.

I have been able to save the file using the details in a specific cell as the file name and save to a temp directory.

Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:="C:\Temp\" & Range("B10").Value _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False

What I can't work out is how to get this PDF file to then open an outlook email template and send the clean up the pdf file.
Ideally I'd like the file name to be in the subject.

I found this code for the email side of things and have modified a few details as to the send to, part of the subject but I am unable to work out what part to change for my dynamic file name to work.

I was trying to define it by using the string "fName" but then I couldn't save the file at all.

Code:
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 = "tyers@mquarry.com.au"
.To = "austtech@aussiebb.com.au"
.Subject = "Customer WOrk Order - "
.Body = "How do I get the PDF to attach correctly??"
.Attachments.Add ("C:\Temp\" & fName & ".pdf")
.Send
End With
Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
.Subject = "Test"
.Body = "How do I get the PDF to attach correctly??"
.Attachments.Add ("C:\Users\Documents\Diagnostic\" & fName & ".pdf")
.Send
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top