XL: Macro Recorder Can't Record Page Setup in Group Mode

Last reviewed: March 27, 1997
Article ID: Q124934
5.00 5.00c 7.00 WINDOWS kbusage kbprg kbcode

The information in this article applies to:

  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows 95, version 7.0

SYMPTOMS

In Microsoft Excel, if you use the macro recorder to record a macro for changing page setup options (such as page orientation or margins) for a group of sheets, the resulting macro only sets the options for the sheet that is active when you recorded the macro--it does NOT set the option for all of the selected sheets as expected.

CAUSE

This problem occurs because the macro recorder records the sheet object as ActiveSheet (which is a single sheet). Therefore, PageSetup becomes a property of a single sheet.

In general, the macro recorder does not work well for recording actions on multiple sheets. For additional information, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q126313
   TITLE     :XL5: Macro Doesn't Function on Multiple Sheets in Group Mode

WORKAROUND

To work around this behavior, modify the macro so that it loops through each sheet in the selection individually, as in the following example:

   Sub ChangePageSetup()
      ' Dimension variable x as Object type
      Dim x As Object
      ' Group select Sheet1, Sheet2, and Sheet3 worksheets
      ' Note that there are other methods for selecting multiple sheets
      Sheets(Array("sheet1", "sheet2", "sheet3")).Select

      ' Change page setup options for sheet
      For Each x In ActiveWindow.SelectedSheets
         With ActiveSheet.PageSetup
            .LeftMargin = Application.InchesToPoints(2)
            .RightMargin = Application.InchesToPoints(2)
            .Orientation = xlLandscape
         End With
      Next x
   End Sub

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.


KBCategory: kbusage kbprg kbcode
KBSubcategory:

Additional reference words: 5.00 5.00c 7.00 wrong page setup improper xl
Keywords : kbcode kbprg kbusage
Version : 5.00 5.00c 7.00
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 27, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.