Excel VBA to print specific pages from multiple sheets into one document

moxygrl88

New Member
Joined
Dec 4, 2014
Messages
7
Platform
  1. Windows
Hi! I'm a beginner with VBA and would greatly appreciate any help or advice.

I have a command button set up on Sheet1 that when you click the button, 3 different worksheets (all in the same workbook) will print, but will only print a certain number of pages from each worksheet. The code I have works well if you are printing to a printer, but if printing to a PDF I would like it to print the pages into one PDF instead of 3 separate PDF files (the code is creating a separate file for each worksheet because of the ActiveWindow.SelectedSheets.PrintOut code, but I don't know how to get the specific page numbers to print for each worksheet without this code).
Sheet1 will always print all pages on worksheet.
Sheet2 will always print page 1, but could print up to page 10 depending on the number of pages to print that is specified in cell A1 on Sheet2.
Sheet3 might not have any pages to print, but could print up to page 10 depending on the number of pages to print that is specified in cell A1 on Sheet3.

Code in Module:
Sub PrintForms()

Sheets("Sheet1").Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False

Sheets("Sheet2").Activate
PageTo = Range("A1").Value
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=PageTo, Copies:=1, Collate:=True, _
IgnorePrintAreas:=False

Sheets("Sheet3").Activate
PageTo = Range("A1").Value
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=PageTo, Copies:=1, Collate:=True, _
IgnorePrintAreas:=False

End Sub


Thank you so much for any help you can offer.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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