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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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