Save sheet as PDF to a set folder and then email it in outlook using set credentials

D3FCON

New Member
Joined
Mar 27, 2017
Messages
7
Hello.

I have tried and edited a few VBA's without luck on what i need to accomplish.

I have a sheet i want to save as a PDF to a pre set folder and then attach it to a new email with certain email address (To, CC1, CC2)

I want to file to save as the name/contents of Cell A3 and also set that cell as the subject for the email.

The sheet should all fit on to the one page on the PDF in landscape mode.

If it matters the sheet name is "Pay Run Sheet"
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
VBA Code:
Option Explicit

Sub MailActiveSheet()
  Dim wPathFile As String

  wPathFile = ThisWorkbook.Path & Range("A3").Value & ".pdf"
  ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & Mid(ThisWorkbook.Path, InStrRev(ThisWorkbook.Path, "\")) & Range("A3").Value & ".pdf", _
    Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

  With CreateObject("Outlook.Application").CreateItem(0)
    .To = "To Address Here"
    .CC = "email1@yahoo.com; email2@gmail.com; email3@tmail.com"
    .Subject = ActiveSheet.Range("A3").Value
    .Body = ""
    .Attachments.Add wPathFile
    .Display
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,864
Members
452,678
Latest member
will_simmo

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