VBA Printing

wid2001

New Member
Joined
Jan 30, 2014
Messages
28
I have an excel Workbook with multiple sheets. I am trying to figure out the code in vba to print two specific worksheets to pdf or straight to the default printer, duplex (Sheet 1 on front and sheet 2 on back. Any help would be appreciated.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Here is something that will save to PDF and your printer.

Code:
Sub PrintOUts()
Dim Printx As String
Dim sCurrentPrinter As String

Setting the current printer to the active printer
sCurrentPrinter = ActivePrinter

Sheets(Array("Sheet1", "Sheet2")).Select 'This is where you change the sheets if you need to
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "INSERT FILE PATH AND NAME OF DOC HERE) & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, OpenAfterPublish:=True


'Notice it has Sheets(ARRAY), this is where you would list all the sheets you want to print
ActivePrinter = sCurrentPrinter
Printx = InputBox("How many copies would you like?")
Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5")).PrintOut Copies:=Printx 'Change worksheets here you want to print








End Sub
 
Upvote 0
So sorry... I left out a ( in the code... Use this below. I just tried it and it works... Make sure on the ARRAY part you replace my SHEET1 and SHEET2 with your own sheet(s)

Code:
Sub PrintOUts()
Dim Printx As String
Dim sCurrentPrinter As String


'Setting the current printer to the active printer
sCurrentPrinter = ActivePrinter


Sheets(Array("Sheet1", "Sheet2")).Select 'This is where you change the sheets if you need to
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    ("FILEPATH\NAME OF DOC") & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, OpenAfterPublish:=True




'Notice it has Sheets(ARRAY), this is where you would list all the sheets you want to print
ActivePrinter = sCurrentPrinter
Printx = InputBox("How many copies would you like?")
Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5")).PrintOut Copies:=Printx 'Change worksheets here you want to print


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,999
Members
452,373
Latest member
TimReeks

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