+ Reply to Thread
Results 1 to 3 of 3

Convert specific sheets to a PDF

  1. #1
    Registered User
    Join Date
    08-29-2012
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    86

    Convert specific sheets to a PDF

    Hi
    I have a spreadsheet that contains 8 different sheets, I would like to be able to set up a button that will convert 6 of those sheets to a PDF each month. I currently have VBA running that will convert to a PDF, however I have to select the sheets to convert before running the Macro, I am hoping to avoid this if possible.
    Current VBA

    Sub PDFActiveSheet()
    'www.contextures.com
    'for Excel 2010 and later
    Dim wsA As Worksheet
    Dim wbA As Workbook
    Dim strTime As String
    Dim strName As String
    Dim strPath As String
    Dim strFile As String
    Dim strPathFile As String
    Dim myFile As Variant
    On Error GoTo errHandler

    Set wbA = ActiveWorkbook
    Set wsA = ActiveSheet
    strTime = Format(Now(), "yyyymmdd\_hhmm")

    'get active workbook folder, if saved
    strPath = wbA.Path
    If strPath = "" Then
    strPath = Application.DefaultFilePath
    End If
    strPath = strPath & "\"

    'replace spaces and periods in sheet name
    strName = Replace(wsA.Name, " ", "")
    strName = Replace(strName, ".", "_")

    'create default name for savng file
    strFile = strName & "_" & strTime & ".pdf"
    strPathFile = strPath & strFile

    'use can enter name and
    ' select folder for file
    myFile = Application.GetSaveAsFilename _
    (InitialFileName:=strPathFile, _
    FileFilter:="PDF Files (*.pdf), *.pdf", _
    Title:="Select Folder and FileName to save")

    'export to PDF if a folder was selected
    If myFile <> "False" Then
    wsA.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=myFile, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False
    'confirmation message with file info
    MsgBox "PDF file has been created: " _
    & vbCrLf _
    & myFile
    End If

    exitHandler:
    Exit Sub
    errHandler:
    MsgBox "Could not create PDF file"
    Resume exitHandler
    End Sub

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Convert specific sheets to a PDF

    Do yourself and us a favo(u)r and read the forum rules again. No 2 is of special interest to you in this case.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Convert specific sheets to a PDF

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. Merging specific rows from specific sheets of multiple files
    By Stevecoop in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2016, 03:11 PM
  2. [SOLVED] VBA Paste Specific Data To Specific Rows On Multiple Sheets
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-13-2014, 09:35 AM
  3. Programming to automatically send text to specific sheets and specific columns.
    By GlobalExcelller in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-21-2014, 10:07 PM
  4. Convert specific number into specific sentence
    By sarangapani in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-26-2013, 03:57 PM
  5. [SOLVED] Insert multiple sheets after convert raw sheets into main
    By PRADEEPB270 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-20-2013, 09:46 AM
  6. Replies: 17
    Last Post: 02-01-2013, 12:20 PM
  7. Copy specific cell from multiple sheets to summary - excluding some sheets
    By kabammi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2012, 09:27 AM

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