Article ID: 109205 - View products that this article applies to.
This article was previously published under Q109205
In Microsoft Excel, if you record a Microsoft Visual Basic for Applications macro that includes a Page Setup command, all of the Page Setup settings are recorded.
Because of this, you may find that running a recorded Visual Basic PageSetup function may take an unusually long amount of time, up to two minutes or more (depending on the speed of your computer). Also, the screen may flicker or blink repeatedly while the function is being executed.
If you record a Page Setup in a Visual Basic macro, all the settings are recorded due to the way in which page setup information is returned to the macro recording system.
The flickering occurs due to the way in which the PageSetup function updates the sheet's different Page Setup settings. The amount of flickering is related to the number of Page Setup settings you change with the PageSetup function: changing more settings results in more flickering.
After you record a Visual Basic PageSetup function, you will probably want to eliminate unneeded settings from the PageSetup function.
To prevent the flickering, set the Application.ScreenUpdating property to False before executing your PageSetup function. Then, when the PageSetup function has completed, you can set the Application.ScreenUpdating property back to True to reenable screen redraws.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The first Visual Basic code example shows the results of recording a Visual Basic PageSetup function.
The second Visual Basic code example shows one way in which you can prevent the screen from flickering or blinking while a PageSetup function is being executed.
Example One - Recording a Page Setup
Because the other settings do not need to be changed, it is not necessary to include them in the subroutine. However, you must remove them yourself.
Also, note that the entire PageSetup procedure can be incorporated into a single With-End With section. It is not necessary for the PrintArea, PrintTitleRows, or PrintTitleColumns settings to be changed separately from the other settings; it is only recorded that way.
Example Two - Preventing Screen Flicker While PageSetup ExecutesThe following subroutine demonstrates one way in which you may prevent the screen from flickering while a PageSetup function is being executed.
The subroutine turns off screen updating just before executing the PageSetup function and then turns screen updating back on when the PageSetup function is complete.
If screen updating is not turned off, as each line in the With section (.PrintTitleRows, .PrintTitleColumns, and so forth) is executed, the screen may flicker slightly.
Article ID: 109205 - Last Review: June 23, 2005 - Revision: 2.0
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.