+ Reply to Thread
Results 1 to 6 of 6

Export Specified Worksheets to PDF

Hybrid View

  1. #1
    Registered User
    Join Date
    04-23-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    37

    Export Specified Worksheets to PDF

    I am looking for a solution similar to the one in this thread.

    http://www.excelforum.com/excel-prog...orksheets.html

    Only difference is I need to export to PDF. I have attempted to modify the code provided with no luck.

    Thanks,

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Export Specified Worksheets to PDF

    Hi, dmarzean,

    maybe have a look at this code (based on the thread you linked):
    Sub ExportRegions_PDF()
    
    'Exports each WorkSheet to a seperate PDF-file and saves it using the Sheet Name
    
    Dim wsCurrent As Worksheet
    Dim strSheetname As String
    Dim strPath As String
    Dim strFileName As String
    Dim lngIndex As Long
    Dim strSkipSheets As String
    
    strPath = "C:\Folder Name\"   '////change this path///
    strSkipSheets = "Overview, Sheet1, Sheet2"
    
    Application.DisplayAlerts = False
    For Each wsCurrent In Worksheets
      If InStr(1, strSkipSheets, wsCurrent.Name) = 0 Then
        strSheetname = wsCurrent.Name
        wsCurrent.Copy
        If Sheets(strSheetname).Range("S1").Value <> "" Then
          strFileName = Sheets(strSheetname).Range("S1").Text
        Else
          strFileName = strSheetname
        End If
        ActiveWorkbook.ExportAsFixedFormat _
          Type:=xlTypePDF, _
          Filename:=strPath & "" & strFileName & ".pdf", _
          Quality:=xlQualityStandard, _
          IncludeDocProperties:=True, _
          IgnorePrintAreas:=False, _
          OpenAfterPublish:=False
        ActiveWorkbook.Close False
      End If
    Next wsCurrent
    
    Application.DisplayAlerts = True
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    04-23-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    37

    Re: Export Specified Worksheets to PDF

    When I run the code from the other post I get same error on this line Sheets(strSheetname).Copy

    My Modifications in rep

    Sub ExportRegions_PDF()
    
    'Exports each WorkSheet to a seperate PDF-file and saves it using the Sheet Name
    
    Dim wsCurrent As Worksheet
    Dim strSheetname As String
    Dim strPath As String
    Dim strFileName As String
    Dim lngIndex As Long
    Dim strSkipSheets As String
    
    strPath = "C:\Users\Douglas\Desktop\integ payroll\Las Vegas 2014\"   '////change this path///
    strSkipSheets = "WorkOrders, Roster, Overrides Perry Pappalalardo, Overrides Phillip Taylor, Overrides Kenneth Imerti, Overrides Danny Sevilla, Overrides David Belikove, Override Sheet Dex Stevens, Overrides James Budd, Invoice Breakdown, Account Database"
    
    Application.DisplayAlerts = False
    For Each wsCurrent In Worksheets
      If InStr(1, strSkipSheets, wsCurrent.Name) = 0 Then
        strSheetname = wsCurrent.Name
        wsCurrent.Copy
        If Sheets(strSheetname).Range("AH9").Value <> "" Then
          strFileName = Sheets(strSheetname).Range("AH9").Text
        Else
          strFileName = strSheetname
        End If
        ActiveWorkbook.ExportAsFixedFormat _
          Type:=xlTypePDF, _
          Filename:=strPath & "" & strFileName & ".pdf", _
          Quality:=xlQualityStandard, _
          IncludeDocProperties:=True, _
          IgnorePrintAreas:=False, _
          OpenAfterPublish:=False
        ActiveWorkbook.Close False
      End If
    Next wsCurrent
    
    Application.DisplayAlerts = True
    End Sub

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Export Specified Worksheets to PDF

    Hi, dmarzean,

    a guess: is the sheet visible if you want to copy it?

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    04-23-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    37

    Re: Export Specified Worksheets to PDF

    Getting same error as when I tried to modify.

    Method 'Copy' of '_Worksheet' failed

    This line highlighted wsCurrent.copy

    How would I modify to use a cell value and nothing to do with the sheet name?

  6. #6
    Registered User
    Join Date
    04-23-2013
    Location
    California
    MS-Off Ver
    Excel 2013
    Posts
    37

    Re: Export Specified Worksheets to PDF

    Well, I feel like an idiot. Didn't even look at my hidden sheets to exclude.

    Your code works perfect!

    Thank you Sir.

+ 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. Export Specified Worksheets
    By HangMan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-19-2014, 01:45 PM
  2. Export Multiple Worksheets to CSV
    By dleininger in forum Excel General
    Replies: 2
    Last Post: 06-23-2013, 02:23 PM
  3. Replies: 1
    Last Post: 10-30-2012, 06:34 PM
  4. Export worksheets
    By mjhopler in forum Excel General
    Replies: 2
    Last Post: 06-14-2010, 01:02 PM
  5. XML Export and worksheets
    By WHoit in forum Excel General
    Replies: 0
    Last Post: 03-15-2005, 07:06 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