Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Macro performance slow when page breaks are visible in Excel


View products that this article applies to.

This article was previously published under Q199505
For a Microsoft Excel 97 version of this article, see 145598 (http://support.microsoft.com/kb/145598/ ) .
For a Microsoft Excel 97 version of this article, see 145598 (http://support.microsoft.com/kb/145598/ ) .

↑ Back to the top


Symptoms

When you run a Microsoft Visual Basic for Applications (VBA) macro in a later version of Microsoft Excel, the macro may take longer to complete than it does in earlier versions of Excel. For example, a macro that required several seconds to complete in an earlier version of Excel may require several minutes to complete in a later version of Excel.

Alternatively, if you run a macro a second time, the macro may take twice as long to run as it did the first time.

↑ Back to the top


Cause

This problem may occur if the following conditions are true:
  • The VBA macro modifies the properties of many rows or columns.
  • You have performed an operation that forced Excel to calculate page breaks. Excel calculates page breaks when you perform any of the following operations:
    • You display a print preview of your worksheet.
    • In Microsoft Office Excel 2003 and in earlier versions of Excel, you click Page Setup on the File menu.

      In Microsoft Office Excel 2007, you click Page Setup on the Quick Access Toolbar.

      Note You may have to add this option to the toolbar manually.
    • You modify any of the properties of the PageSetup object in a VBA macro.
  • In Excel 2003 and in earlier versions of Excel, you select the Page breaks check box on the View tab of the Options dialog box.

    In Excel 2007, you click the Microsoft Office Button, click Excel Options, click the Advanced category, and then click to select the Show page breaks check box under the Display options for this worksheet section.
This problem occurs if your macro sets any PageSetup property, or if you manually set a PageSetup property, and then run a VBA macro that sets properties on a large range of rows or columns.

When you set a PageSetup property, automatic calculation of page breaks is enabled in Excel. By default, this property is not set.

↑ Back to the top


Workaround

To work around this issue, use either of the following methods.

Method 1: Manually disable the page breaks display

To do this in Excel 2003 and in earlier versions of Excel, follow these steps:
  1. Click Options on the Tools menu.
  2. Click the View tab. Under Window options, click to clear the Page breaks check box. Click OK.
To do this in Excel 2007, follow these steps:
  1. Click the Microsoft Office Button, and then click Excel Options.
  2. Click the Advanced category, and then click to clear the Show page breaks check box under the Display options for this worksheet section.

Method 2: Disable the page breaks display programmatically

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.

To disable the page breaks display programmatically, add the following line of code to your VBA macro.
ActiveSheet.DisplayPageBreaks = False
				
Important You must insert this line of code after you modify any of the properties of the PageSetup object, but before you modify the properties or the rows on your worksheet.

↑ Back to the top


Keywords: KB199505, kbprint, kbprb, kbdtacode

↑ Back to the top

Article Info
Article ID : 199505
Revision : 6
Created on : 1/23/2007
Published on : 1/23/2007
Exists online : False
Views : 446