+ Reply to Thread
Results 1 to 5 of 5

Send PDF to E-mail with Macro

  1. #1
    Registered User
    Join Date
    08-11-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    1

    Send PDF to E-mail with Macro

    Hi,

    I have a macro that will toggle through a pivot table, save each report as a pdf into a folder, and print the report. Is it possible to have it send each pdf to outlook with a specific message in the text?

    PHP Code: 
    Option Explicit

       
    Sub MakePDF
    ()

    If 
    Dir(ThisWorkbook.Path "\" & MonthName(Month(Date)), vbDirectory) = MonthName(Month(Date)) Then
            MsgBox "
    Folder already exists!"
        Else
            MkDir Application.ThisWorkbook.Path & "
    \" & MonthName(Month(Date))
          End If
            
    Dim shC As Worksheet        ' Collection Officer worksheet
    Dim pt As PivotTable        ' Pivot Table
    Dim pf As PivotField        ' Pivot field
    Dim pi As PivotItem         ' Pivot item
    Dim LrowC As Long           ' Last row on worksheet.
    Dim cl As Range             ' Pointer to list of collection officers


    Dim PathName As String      ' Path to PDF File (current folder)
    Dim FileName As String      ' PDF FileName

    ' initalize variables
    Set shC = Sheets("
    Collection Officer")
    Set pt = shC.PivotTables(1)
    Set pf = pt.PivotFields("
    Collection Officer")

    PathName = ThisWorkbook.Path & "
    \" & MonthName(Month(Date))


    For Each cl In Range("
    Collection_Officers")
        ' Get last row
        LrowC = shC.Range("
    A" & Rows.Count).End(xlUp).Row
        
        ' Make file name and set the print area
        FileName = cl.Value & "
    .pdf"
        shC.PageSetup.PrintArea = "
    $A$1:$E$" & LrowC
        
        ' Filter the pivot table
        pf.ClearAllFilters                      ' Clear the old filter to show all
        For Each pi In pf.PivotItems            ' Turn off items we don't want to see
            If pi.Value <> cl.Value Then
                pi.Visible = False
            End If
        Next pi

    ' Print - added by callum
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
            IgnorePrintAreas:=False
        ActiveWindow.SmallScroll Down:=-60
        Range("
    A1").Select

        ' Publish as PDF
         shC.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
            PathName & "
    \" & FileName, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    Next cl

    ' clear pivot table
     pf.ClearAllFilters
            
    End Sub 
    Thanks!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Send PDF to E-mail with Macro

    Should be. Have a look at Ron de Bruin’s web site: https://www.rondebruin.nl/win/section1.htm
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-14-2019
    Location
    Essex
    MS-Off Ver
    2016
    Posts
    19

    Re: Send PDF to E-mail with Macro

    Thanks TMS that was really helpful,

    I'm having a problem attaching the pdf to the e-mails but will try to figure it out alone first.
    Last edited by callumlmcgrath; 05-01-2019 at 09:41 AM.

  4. #4
    Registered User
    Join Date
    03-14-2019
    Location
    Essex
    MS-Off Ver
    2016
    Posts
    19

    Re: Send PDF to E-mail with Macro

    Hey,

    I'm almost there but can't figure out why the PDF isn't actually attaching to the e-mail?

    I have attached the example doc I am using if you are able to help.

    Thanks,

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,434

    Re: Send PDF to E-mail with Macro

    Not near a computer at the minute will try to have a look this evening.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need to send a mail using macro
    By Prabakaran3003 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-10-2016, 03:04 PM
  2. Replies: 1
    Last Post: 03-11-2014, 12:24 PM
  3. How to e-mail selected row and use e-mail address in a cell to send e-mail from excel
    By syedalamgir in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2010, 02:15 AM
  4. Send Mail Macro
    By jregan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2010, 07:34 PM
  5. Excel Send Mail Macro
    By jregan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-10-2010, 12:33 PM
  6. Send Mail Macro
    By jregan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2010, 03:50 PM
  7. using macro to send e-mail
    By bob777 in forum Excel General
    Replies: 1
    Last Post: 11-02-2005, 07:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1