Select All Sheets VBA code

markjlang

New Member
Joined
Jun 19, 2006
Messages
28
Hi there

Not sure of VBA code here. I'd like to select all sheets in VBA. Recoding macro does not work. I need to select all and then set print settings to print one page per sheet.

Many thanks
Mark
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,887
Hi Mark

To select all sheets try:

Worksheets.Select

Hope this helps
PGC
 

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
I don't know about the printing, but selecting all of the sheets should be as simple as using Sheets.Select.
 

markjlang

New Member
Joined
Jun 19, 2006
Messages
28
Thanks that's done the trick.

Just wish I could loop through the sheets and set them each to print on one page. :(
 

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
Code:
Sub PrintPageOne()
    Dim ws As Worksheet
    Dim CurSheet As Worksheet
        Set CurSheet = ActiveSheet
        For Each ws In ActiveWorkbook.Worksheets
            ws.Activate
            ActiveSheet.PrintOut _
                From:=1, To:=1, Copies:=1, Collate:=True
        Next ws
        CurSheet.Activate
End Sub
 

markjlang

New Member
Joined
Jun 19, 2006
Messages
28
Thanks Datsmart

Unfortunately it doesn't set the print settings to fit one page. Any ideas here?

Cheers
M
 

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
This will set each page setting to print entire sheet on one page. Then printout each page.
Code:
Sub PrintPageOne()
    Dim ws As Worksheet
    Dim CurSheet As Worksheet
        Set CurSheet = ActiveSheet
        For Each ws In ActiveWorkbook.Worksheets
            ws.Activate
            With ActiveSheet.PageSetup
                .FitToPagesWide = 1
                .FitToPagesTall = 1
            End With
            ActiveSheet.PrintOut
        Next ws
        CurSheet.Activate
End Sub
 

Forum statistics

Threads
1,171,273
Messages
5,874,777
Members
433,071
Latest member
llokjj

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
Top