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,
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,
Hi, dmarzean,
maybe have a look at this code (based on the thread you linked):
Ciao,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
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
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
Hi, dmarzean,
a guess: is the sheet visible if you want to copy it?
Ciao,
Holger
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?
Well, I feel like an idiot. Didn't even look at my hidden sheets to exclude.
Your code works perfect!
Thank you Sir.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks