Printing not working for multiple sheets

mcomp72

Active Member
Joined
Aug 14, 2016
Messages
305
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have written code to allow the user to create a PDF of whichever sheets of the workbook they want included. My code works perfectly. It is:

Code:
Dim SheetsToPrint As String

... code here determines what 'SheetsToPrint' is equal to ...

Sheets(Split(SheetsToPrint, ",")).Select

ActiveSheet.ExportAsFixedFormat _
                Type:=xlTypePDF, _
                filename:=PDFName, _
                Quality:=xlQualityStandard, _
                IncludeDocProperties:=True, _
                IgnorePrintAreas:=False, _
                OpenAfterPublish:=False

What I want to do now is remove the "ExportAsFixedFormat" line and replace it with a line to print a hard copy of the selected sheets. I have tried it with this code:

Code:
Dim SheetsToPrint As String

... code here determines what 'SheetsToPrint' is equal to ...

Sheets(Split(SheetsToPrint, ",")).Select

ActiveSheet.PrintOut Preview:=False, IgnorePrintAreas:=False

That code will only print the FIRST sheet in the selected sheets, and I can't for a life of me figure out why. Any idea why the PDF creation works fine for multiple sheets but when printing a hard copy it will only print the first one?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I figured it out. After digging around on the web, I found a page that gave me the idea of trying to change my PrintOut line to this:

Code:
Sheets(Split(SheetsToPrint, ",")).PrintOut Preview:=False, IgnorePrintAreas:=False

It worked!
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,629
Members
452,661
Latest member
Nonhle

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