VBA Page Setup Code taking too long

Drofidnas

Board Regular
Joined
Jun 30, 2004
Messages
126
Morning

I have the following VBA code to set the margins and footers of my page. The trouble is, each . step is taking 3 seconds to execute, meaning the whole snippet takes over a minute to run. It's part of a bigger macro which executes in under 5 seconds so this whole section is causing the lag.
Any idea why this might be or am I not using the code efficiently?
Code:
ActiveSheet.PageSetup.PrintArea = "$A$1:$E$17"

With ActiveSheet.PageSetup
        .RightMargin = Application.InchesToPoints(0.99)
        .LeftMargin = Application.InchesToPoints(0.4)
        .TopMargin = Application.InchesToPoints(0.88)
        .BottomMargin = Application.InchesToPoints(0.91)
        .HeaderMargin = Application.InchesToPoints(0.4)
        .FooterMargin = Application.InchesToPoints(0.63)
        .LeftFooter = "    2-" & Worksheets("2_ADS_Data").Range("O" & rng)
        .RightFooter = ""
        .LeftHeader = "    " & Worksheets("2_ADS_Data").Range("B1")
        .RightHeader = ""
End With

Cheers

Chris
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
There is the following option, but I think it only applies from Excel 2010 & later.
Code:
Application.PrintCommunication = False

'Your page setup code here

Application.PrintCommunication = True
 
Last edited:
Upvote 0
Wow that did the trick. Many thanks.

I've not touched this spreadsheet for about 6 months and I swear it used to be quicker so maybe other commands such as Application.Screenupdating (which I regularly use) have a bearing on this as well.

Cheers Peter
 
Upvote 0

Forum statistics

Threads
1,215,549
Messages
6,125,473
Members
449,233
Latest member
Deardevil

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