Results 1 to 1 of 1

VBA help to email printed pagebeak to a email address

Threaded View

arun1024 VBA help to email printed... 12-25-2018, 08:55 AM
  1. #1
    Registered User
    Join Date
    12-25-2018
    Location
    England
    MS-Off Ver
    365
    Posts
    1

    VBA help to email printed pagebeak to a email address

    Hi All,

    I need help with the following VBA, At the minute the VBA can print page break to pdf and name them according to the name found in cell A and has loop to pint all page breaks as pdf. I was wondering if there' was a way, it could also email the pdfs generated to individual email address. I have roughly 20 page breaks and all those need to be emailed to different email addresses according to the names.

    Sub exportPages()
    Set Sht = Worksheets("Sheet1")
    ' The variable Sht now holds the sheet that should be printed, so we can use that in the macro instead of repeating Worksheets("Sheet1")
    ExportDir = "C:\Users\Desktop\"
    ' A string/text with the export directory, should end with a \
    NrPages = Sht.HPageBreaks.Count + 1
    ' Using the Sht object, count the number of horizontal page breaks and add one to know the number of pages
    For p = 1 To NrPages
    ' Loop though the pages, actually the loop is only there as a kind of "counter"
    If p = 1 Then
    RwStart = 1
    ' The first page starts at the top and has no page break before it, so the row with your name is 1
    Else
    RwStart = Sht.HPageBreaks(p - 1).Location.Row
    ' Page 2 starts after Pagebreak 1, this code finds the row of the page break (=the row directly after it)
    End If
    FoundName = Sht.Range("A" & RwStart).Value
    ExportName = FoundName & p & ".pdf"
    ' Create a variable with the name in the sheet
    Sht.ExportAsFixedFormat Type:=xlTypePDF, filename:=ExportDir & ExportName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, From:=p, to:=p, OpenAfterPublish:=False
    ' Export the current page with the current name to the default location
    Next
    Set Sht = Nothing
    ' Clean up variables
    End Sub

    Thanks in Advance


    Regards
    Last edited by jeffreybrown; 12-25-2018 at 09:51 AM. Reason: Please use code tags!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] vba email send from excel - ignore second email address if "ENTER EMAIL ADDRESS"
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-28-2016, 07:22 AM
  2. Email a screenshot of a specifc row in an email to a specfic email address
    By Cobra75007 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-19-2015, 10:36 AM
  3. attach different worksheet and email them tdifferent email address through macro/vba/addin
    By arunverma004 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-03-2014, 08:20 AM
  4. [SOLVED] Extracting email chain email address and converting to Excel column
    By Leah_Hael in forum Excel General
    Replies: 4
    Last Post: 12-28-2012, 04:05 PM
  5. Macro to PDF a sheet in workbook and email (outlook) to an email address in a cell
    By paul_sykes00 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-17-2012, 12:54 AM
  6. Replies: 1
    Last Post: 03-08-2012, 01:57 PM

Tags for this Thread

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