Print to PDF as name of each sheet.

derek.hughes

Board Regular
Joined
Mar 16, 2012
Messages
53
I have a spreadsheet exported from Access that contains each department's budget information (used, remaining, etc.).

I want to create a command button that when clicked will create a separate PDF for each worksheet. I want each .PDF file to be named the same as the Worksheet name.

Can you help?

Derek
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Code:
Sub SheetsToPDF()
    Dim DestinPath As String
    Dim sh As Worksheet
    
    DestinPath = "C:\XLtest\"
    
    Rem This overwrites any existing PDF w/ no warning
    
    For Each sh In ActiveWorkbook.Worksheets
        If WorksheetFunction.CountA(sh.Cells) > 0 Then
            sh.ExportAsFixedFormat Type:=xlTypePDF, _
                Filename:=DestinPath & sh.Name, _
                Quality:=xlQualityStandard, _
                IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, _
                OpenAfterPublish:=False
        End If
    Next sh
End Sub
 
Upvote 0
Thank you, Warship. I set up a button, pasted the code in as a macro, changed the destination, and it says "publishing" but it does not appear. What am I doing incorrectly?

Could you give me steps as to where to paste?

Thank you,

Derek
 
Upvote 0
if it says "publishing" it is working.
go to the destination fold with Windows and you'll see it there.

if you want it to open right after publishing change this line to =True
Code:
OpenAfterPublish:=False

Blank sheets are skipped
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top