Setup page layout in VBA

olympiac

Board Regular
Joined
Sep 26, 2010
Messages
158
I am running the code below to setup the Page layout of my spreadsheet.
Do you why it's taking so long when I run it?
Do you know why the line ".CenterFooter = "&[Tab]" instead of giving me the name of the sheet, it gives me the value "[TAB]" in my print preview

With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.Orientation = xlLandscape

.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = Application.InchesToPoints(0.7)
.TopMargin = Application.InchesToPoints(0.98)
.BottomMargin = Application.InchesToPoints(0.98)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)

.CenterFooter = "&[Tab]"


Thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Page setup code tends to run slowly because Excel interacts with the printer drivers. Try this

Code:
.CenterFooter = ActiveSheet.Name
 
Upvote 0
Add/Modify in RED

Rich (BB code):
.....
.FooterMargin = Application.InchesToPoints(0.5)
T = ActiveSheet.Name
.CenterFooter = T
End With
 
Upvote 0
Those footers will not automatically update if the sheet name is changed. I would suggest this which will auto-update:
Code:
.CenterFooter = "&A"


In relation to the speed, VoG has indicated the cause. If you have Excel 2010 you can turn off/on the interaction with the printer to speed the code:
Code:
Application.PrintCommunication = False

    With ActiveSheet.PageSetup

        ' Page setup items here

    End With

Application.PrintCommunication = True

In earlier versions you can, with a bit of effort, get around the speed issue by
- recording the current printer
- setting the printer to a printer like a pdf printer (might need a bit of trial & error to see which one works fast)
- doing the page setup
- setting the printer back to the recorded value.
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

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