Microsoft KB Archive/124934

= Macro Recorder Can't Record Page Setup in Group Mode =

Article ID: 124934

Article Last Modified on 8/15/2005

-

APPLIES TO


 * Microsoft Excel 95 Standard Edition
 * Microsoft Excel 5.0c

-



This article was previously published under Q124934





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:

126313 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.

Additional query words: 5.00c wrong page setup improper xl

Keywords: KB124934

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.