Macro to set print format for workbook

AvgMSUser

New Member
Joined
Dec 22, 2015
Messages
8
I have a workbook with multiple worksheets set to show/hide. I've created the below macro as a start to set the printing format so that it doesn't change for the users. I have two questions: 1) will the print settings apply when the users save the document in pdf format, and 2) how do I get the macro's Array to include only the worksheets the user completed?

I've tried various ways to get the macro to reference a cell within the workbook that lists only the worksheets that need to be printed but they didn't work. I'd appreciate all guidance provided as I'm still relatively new to macros.

Code:
Sub PrintWorkbook()

Sheets(Array("Welcome!", "Summary Tab")).Select
Sheets("Welcome!").Activate
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False

End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Thank you. I don't completely understand what I read but I'll play with my macro to see if I can correctly have it reference the dynamic array I have built.
 
Upvote 0
Hi AvgMSUser,

The idea is simple, use the Replace parameter of Worksheet.Select(Replace).

In the beginning set Replace = True to select the first worksheet in the array then set to False to extend the array by adding more worksheets.

Hope this is clear.
 
Upvote 0
Thanks Mohammad. I'm slow as I'm still a beginner with macros but this is beginning to make more sense.
 
Upvote 0
Mohammad, thanks again for your help. I wasn’t able to get the code you provided working but discovered the below code that suits my purposes. As long as the users don’t hide a worksheet they used, this code will print all of the necessary worksheets.

It is a little slow but I am assuming it is because each sheet is being checked to make sure it isn’t either “US” or “Canadian” worksheets</SPAN>

Code:
Dim wSheet As Worksheet</SPAN>
 
For Each wSheet In ActiveWorkbook.Worksheets</SPAN>
If wSheet.Visible = xlSheetVisible Then</SPAN>
    If wSheet.Name <> "U.S. " Then</SPAN>
    If wSheet.Name <> "Canadian" Then</SPAN>
            wSheet.PrintOut</SPAN>
    End If</SPAN>
    End If</SPAN>
End If</SPAN>
</SPAN>
 
Upvote 0
Hi AvgMSUser,

Try this,

Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]Sub PrintMultipleSheets()

   Dim wSheet As Worksheet
   Dim bl1stSheet As Boolean

   bl1stSheet = True
   For Each wSheet In ActiveWorkbook.Worksheets
      With wSheet
         If .Visible = xlSheetVisible And .Name <> "U.S. " And wSheet.Name <> "Canadian" Then
            .Select bl1stSheet
            bl1stSheet = False
         End If
      End With
   Next wSheet
   ActiveWindow.SelectedSheets.PrintPreview
   ActiveWindow.SelectedSheets.PrintOut
   ActiveSheet.Select
   Set wSheet = Nothing

End Sub[/COLOR][/SIZE][/FONT]
 
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,965
Members
449,201
Latest member
Jamil ahmed

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