RunPages and Print Page 1 of each worksheet

alipaska

New Member
Joined
May 13, 2005
Messages
38
Hey guys,

please help me. This should be really simple for you but I can't figure out why it doesn't run the pages and print each of them. This is the code:

Sub Macro()

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
With ws
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
End With
Next ws

End Sub

Thanks a lot.
Ali
 

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.
Hello alipaska,
Let me guess. It's printing the active sheet the number of times as the number of sheets you have. (?)

Try selecting each sheet in your loop...
Code:
Sub Macro()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    ws.Select
    With ActiveSheet
        .PrintOut From:=1, To:=1, Copies:=1, Collate:=True
    End With
Next ws
End Sub
Hope it helps.
 
Upvote 0
Hi Ali,

Just modified your code slightly, you were refering to the Activewindow.selectedSheets which would only ever print the same page.

Code:
Sub Macro()
    Dim ws As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            With ws
                 .PrintOut From:=1, To:=1, Copies:=1, Collate _
                 :=True
            End With
        Next ws
End Sub

HTH Brett
 
Upvote 0
Thank you so much. It works :biggrin:

I do have one more question though: if I want to do the same thing but only for specific worksheets in the workbook, how would I do that?

Thanks again for your help.

Ali
 
Upvote 0
The best way to do that would depend on if there are (will be) only specific sheets you want to print, or specific sheets that you dont want to print.

In either case, if the sheet names will remain the same, can you provide their names?
 
Upvote 0
What if the sheets were called Sheet3-Sheet10, the ones I want to print. How would the code look like?

Thanks again,
Ali
 
Upvote 0
Ali

Maybe something like this?
Code:
Sub Macro()
Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        With ws
            Select Case Mid(ws.Name, 5)
                Case 3 To 10
                    .PrintOut From:=1, To:=1, Copies:=1, Collate:=True
                Case Else
                            ' Do nothing
            End Select
        End With
    Next ws
End Sub
 
Upvote 0
Would that work for each tab named differently (for example : revenues, sales, profit, department1, department2 etc). Can it be applied generally, that it would always print sheets 3-10 (case 3 to 10)? Will I still be able to print last 7 tabs out of 10 with this code?

Thanks,
Ali
 
Upvote 0
Hello, alipaska,

you can loop through the sheets using their indexnumbers
Sheets(i).Select
using Halfaces code
Code:
Sub Macro() 
Dim ws As Worksheet
Dim i As Integer
For i = 3 to 10
    Sheets(i).Select 
    With ActiveSheet 
        .PrintOut From:=1, To:=1, Copies:=1, Collate:=True 
    End With 
Next i
End Sub
kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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