VBA required to export individual sheets to indivdual pdfs

rossa

Board Regular
Joined
Nov 7, 2013
Messages
109
Hi. I have a file where the first sheet feeds data to the other sheets (the number of sheets may vary over the months). I need all these sheets saved separately into their own pdf file. Is it possible to get a code that will save each sheet into its own pdf in the same location as the excel file itself is saved?
I have searched this forum and others, but I can't find a code that works (most errors seem to arise from the worksheet Dim ws).
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try that:
Backup before test, test in a throw away copy of your file.

VBA Code:
Sub Test()

Dim oSht As Worksheet, oWkb As Workbook

Set oWkb = ActiveWorkbook
Application.ScreenUpdating = False
For Each oSht In oWkb.Sheets
    oSht.ExportAsFixedFormat xlTypePDF, oWkb.Path & "\" & oSht.Name & ".pdf"
Next oSht
Set oWkb = Nothing
Application.ScreenUpdating = True

End Sub
 
Last edited:
Upvote 0
Thanks for your response. Unfortunately I am getting an error
"Run time error 5
Invalid procedure call or arguement"

This seems to be the offending line.
oSht.ExportAsFixedFormat xlTypePDF, oWkb.Path & "\" & oSht.Name & ".pdf"
 
Upvote 0
Must not have hidden worksheets.
If there's hidden worksheet do you want to save those one as pdf also?
 
Upvote 0
Ah, the hidden worksheets! Iforgot about that. Removed them and it it worked perfectly. I appreciate your help, happy new year!
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,060
Latest member
mtsheetz

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