Macro Slow Running for Page Setup Setting

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..
This lengthy statement adjusts the page setup properties on the active sheet, and is equivalent to this slower (but newer) method
cross post Faster Alternatives to VBA PageSetup - wellsr.com
here code :
VBA Code:
Sub SlowPageSetup_Loop()
For Each sht In ActiveWorkbook.Sheets
    With sht.PageSetup
        .Zoom = False
        .Orientation = xlLandscape
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.CentimetersToPoints(5)
        .BottomMargin = Application.InchesToPoints(0.5)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .FitToPagesWide = 2
        .FitToPagesTall = 1
        .CenterHorizontally = True
        .CenterVertically = False
    End With
Next sht
End Sub

how to make faster not slowly..
note : i use Ms Office 2010 till 2016

thank in advance

.sst
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You should be able to group the sheets first

VBA Code:
Sub GroupTabs()
    For i = Sheets(1).Index To Sheets(Sheets.Count).Index
        Sheets(i).Select Replace:=False
    Next i
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .Zoom = False
        .Orientation = xlLandscape
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.CentimetersToPoints(5)
        .BottomMargin = Application.InchesToPoints(0.5)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .FitToPagesWide = 2
        .FitToPagesTall = 1
        .CenterHorizontally = True
        .CenterVertically = False
    End With

End Sub
 
Upvote 0
You should be able to group the sheets first

VBA Code:
Sub GroupTabs()
    For i = Sheets(1).Index To Sheets(Sheets.Count).Index
        Sheets(i).Select Replace:=False
    Next i
    Application.PrintCommunication = False
    With ActiveSheet.PageSetup
        .Zoom = False
        .Orientation = xlLandscape
        .LeftMargin = Application.InchesToPoints(0.25)
        .RightMargin = Application.InchesToPoints(0.25)
        .TopMargin = Application.CentimetersToPoints(5)
        .BottomMargin = Application.InchesToPoints(0.5)
        .HeaderMargin = Application.InchesToPoints(0.3)
        .FooterMargin = Application.InchesToPoints(0.3)
        .FitToPagesWide = 2
        .FitToPagesTall = 1
        .CenterHorizontally = True
        .CenterVertically = False
    End With

End Sub
hi Dave, thanks a lot , once again how to your code can combined with code below, i want to single run macro.
Excel Formula:
Sub Insert_Current_Total_Page_Number_Footer()
'declare a variable
Dim ws As Worksheet

Set ws = Worksheets("Sheet1")
With ws.PageSetup
.CenterFooter = "&10&P of &N"
End With

End Sub
 
Upvote 0
I just randomly picked a line and placed your code in there.

1600875176768.png
 
Upvote 0

Forum statistics

Threads
1,215,529
Messages
6,125,344
Members
449,219
Latest member
Smiqer

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