Macro for printing mulitple sheets in workbook

yellowcabguy

Active Member
Joined
Dec 28, 2005
Messages
440
I have a workbook thatt has 18 sheets and I want to print sheets 4-18. Is there a way, rather than printing each sheet individually that I can create a macro that prints all of the designated 15 sheets with the click of a button??
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You can use the following code to print the designated worksheets.
Code:
Sub PrintSomeWorkSheets()
Dim ws As Worksheet
    For Each ws In Worksheets
        Select Case Mid(ws.CodeName, 6) 'Get Number of sheet 6 places in
            Case 1, 2, 3, 4
                ws.PrintOut
            Case Else
                ' do nothing
        End Select
    Next ws
End Sub
I have only listed 4 sheets in my code, you can add the ones you want printed. You will have to list their "CodeName" as shown when viewed in the VB Editor. Codename 1 is not necessarily sheet 1, it is the first sheet created by excel. Even if you add or remove sheets, sheet codenames do not change.
 
Upvote 0
Macro to print mulitple sheets

Thanks a bunch

This is the macro I put in. When I hit run it is printing the 4 sheets I want (sheets 5,6,7 & 8). Doe sit look right? Not sure I understand "CodeName"

Sub PrintSomeWorksheets()
Dim ws As Worksheet
For Each ws In Worksheets
Select Case Mid(ws.CodeName, 6) 'Get Number of sheet 5 places in
Case 5, 6, 7, 8
ws.PrintOut
Case Else
' do nothing
End Select
Next ws
End Sub

The Case # refers to the specific sheets which I want to print. IF I want to print everything after(inlcuding ) sheet "5", is there a way to do that.
I will be adding new sheets as I go along and want to see if there is a way not to have to change the MACRO when I add new sheets.
 
Upvote 0
Change this line of code:
Code:
Case 5, 6, 7, 8
to
Code:
Case Is > 4
That should print out all sheets with codenames 5 and above.
 
Upvote 0
Priinting Macro

Okie Dokie will make the recommended change.

In the code -what does "Select Case Mid(ws.CodeName, 6) 'Get Number of Sheet 5 places" mean or do??

Now for another curve ball.

Lets assume I want to print any sheet greater than sheet 4 THAT has a specific date (TODAY) in a specific cell (E7) on each sheet.

Can a Macro decide which of the sheets have TODAY in E7 and only print those??

Really appreciate your great help.

Where in Washington are you. Wife and I are thinking of moving out to the Olympic Penisula
 
Upvote 0
Your request to print sheets that have a specific date is a whole different procedure. Won't be able to incorporate the two methods together. At least not with the code I gave you so far. But code can do what you are asking, just a whole new thought process.

In the code, "Mid(ws.CodeName, 6)", is getting the number portion of the codename. That number starts in position 6 of the codename. If you open a new workbook, sheet1's codename will be "Sheet1" the "1" starts in postion 6 of that name.
The Select Case portion of the code sets what follows, the codename #, as the number to use in the rest of the code.

I am in a small town called Elma, south end of the Olympic pennisula. Olympic forest is about 40 miles north of town. Elma is about half way between the south end of Puget Sound and the ocean. Lots of rain, but mild summer and winters.
Where are you located now?
 
Upvote 0
Try this code:
Code:
Sub PrintSomeWorkSheets()
Dim ws As Worksheet
    For Each ws In Worksheets
        Select Case Mid(ws.CodeName, 6) 'Get Number of sheet 6 places in
            Case Is > 4
                If Range("E7").Value = Date Then
                    ws.PrintOut
                End If
            Case Else
                ' do nothing
        End Select
    Next ws
End Sub
It looks at cell E7 of the worksheet that is being checked, if the value is equal to Today's date, then it prints.
Edit: Replaced "[(Today())]" with "Date".
 
Upvote 0
Another option, in case your desired list of worksheets to be printed changes from time to time (as mine does).

Hold down the Ctrl key, and select only the worksheets you want to print.
 
Upvote 0

Forum statistics

Threads
1,225,157
Messages
6,183,248
Members
453,152
Latest member
ChrisMd

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