VBA - Print to PDF?

jworkman7

Board Regular
Joined
Jul 1, 2015
Messages
50
I have a simple macro command button with the following script:

Sub PrintVisibleOnly()
Dim wsh As Worksheet
For Each wsh In ActiveWorkbook.Worksheets
If wsh.Visible = xlSheetVisible Then
wsh.PrintOut
End If
Next wsh
End Sub

This macro automatically prints the selected print area of any visible tabs. I would like to amend it slightly (or add another command button) with a macro which will instead of printing out the sheets to the default printer, simply print to PDF. Is anyone aware of any code I can input here?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
If you record a macro to save the active sheet as the PDF type then it will generate the code which you can incorporate into your macro.

PS please use CODE tags.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,403
Members
452,325
Latest member
BlahQz

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