Print Preview selected sheets

Hudco

Board Regular
Joined
Jan 4, 2006
Messages
125
Office Version
  1. 365
I have a workbook with sheets named Control, Temp, Start, End & Tax. An active X button will copy the Temp sheet between Start & End. The number of sheets created will depend on the number of employees with one employee per sheet. Each of the sheets created from the Temp sheet is renamed with a unique name.

I am trying to create a macro which will print to preview as one run all the employee sheets. The employee sheets will already have the print area specified (same on every sheet). I know I can just hihlight all the required sheets but I am trying to automate for people with limited excel skills.

Can anyone help,
Thank you
 

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
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

See if this is any use. If you want the option to actually print after the preview then uncomment the line near the end of the code.

VBA Code:
Sub Print_Preview_Employees()
  Dim wsAct As Worksheet
  Dim i As Long
  Dim ShtNames As String
  
  Set wsAct = ActiveSheet
  For i = Sheets("Start").Index + 1 To Sheets("End").Index - 1
    ShtNames = ShtNames & "?" & Sheets(i).Name
  Next i
  Sheets(Split(Mid(ShtNames, 2), "?")).PrintPreview
'  If MsgBox("Confirm to print?", vbYesNo) = vbYes Then ActiveWindow.SelectedSheets.PrintOut
  wsAct.Select
End Sub
 
Upvote 0
Solution
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

See if this is any use. If you want the option to actually print after the preview then uncomment the line near the end of the code.

VBA Code:
Sub Print_Preview_Employees()
  Dim wsAct As Worksheet
  Dim i As Long
  Dim ShtNames As String
 
  Set wsAct = ActiveSheet
  For i = Sheets("Start").Index + 1 To Sheets("End").Index - 1
    ShtNames = ShtNames & "?" & Sheets(i).Name
  Next i
  Sheets(Split(Mid(ShtNames, 2), "?")).PrintPreview
'  If MsgBox("Confirm to print?", vbYesNo) = vbYes Then ActiveWindow.SelectedSheets.PrintOut
  wsAct.Select
End Sub
 
Upvote 0
Thanks Peter,
Worked well.
And I updated record - didn't realise that had all changed.

Thanks,
Clyde
 
Upvote 0
You're welcome. Thanks for the follow-up. :)

.. and for updating your details. (y)
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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