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.
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.