Export & Email

Tangles

New Member
Joined
Jul 20, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

Before I start, I just want to make it known that I'm not necessarily new to programming but I'm relatively new to VisualBasic, so bear with me!

I'm trying to create a macro that will export the current sheet as a PDF file, and send it as an attachment on an email to predetermined recipients with a predetermined subject.

I've tried using the "ActiveWorkbook.SendMail" function but it doesn't export as a PDF, and I can't seem to get the string right for the Recipients object to send to multiple recipients.

I'd like the least amount of user input as possible (ie I click the button, and it exports and sends the email without input).

Any help is greatly appreciated.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Here is something you can work with to get started.

Ths saves the pdf to your temp folder.
Then attaches the file to your email.

VBA Code:
Sub EmailOnePDFSheet()
    Dim oApp As Object
    Dim oMail As Object
    Dim wb As Workbook
    fName = Environ("Temp") & "\copySheet.pdf"

    'Turn off screen updating
    Application.ScreenUpdating = False
    'PDF sheet and save it to a temporary file
    Sheet1.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fName

    'Create and show the outlook mail item
    Set oMail = CreateObject("Outlook.Application").CreateItem(0)
    With oMail    'Add a recipient
        .To = "Marcus.Small@YourEmail.com.au"
        .Subject = "One Page Activesheet v2"
        .Attachments.Add fName
        .Display
    End With

    Application.ScreenUpdating = True
    Set oMail = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,023
Latest member
alabaz

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