XL: How to Set Page Setup Attributes for More Than One Sheet (213257)
The information in this article applies to:
- Microsoft Excel 2000
- Microsoft Excel 2002
This article was previously published under Q213257 For a Microsoft Excel 97 and earlier and Microsoft Excel 98 Macintosh Edition and earlier version of this article, see 154663.
SUMMARY
In Microsoft Excel, page setup attributes, such as margins, sheet orientation, and print titles, are set for each worksheet, individually. This article describes three methods that you can use to set some of these attributes globally.
MORE INFORMATION
To set page setup attributes for a group of Excel worksheets, use one of the following methods.
Method 1: Use a TemplateFor more information about using templates to save page setup attributes, click Microsoft Excel Help on the Help menu, type customize the defaults for a workbook or worksheet by using a template in the Office Assistant or the Answer Wizard, and then click Search to view the topic. Method 2: Change a Group of Worksheets
To apply page setup attributes to a group of worksheets in a workbook, follow these steps:
- Press SHIFT and then click each worksheet tab in the workbook that you want to affect.
- On the File menu, click Page Setup.
- Make the changes that you want in the Page Setup dialog box, and then click OK.
All of the worksheets that you selected have the same page setup attributes.
Method 3: Use a MacroMicrosoft provides programming examples 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 article assumes
that you are familiar with the programming language being demonstrated and the
tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may
want to contact a Microsoft Certified Partner or the Microsoft fee-based
consulting line at (800) 936-5200. For more information about Microsoft Certified
Partners, please visit the following Microsoft Web site:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
You can programmatically change the page setup attributes in the active workbook and in any other open workbook. NOTE: These macros use the Orientation property of the PageSetup object. You can modify other page setup attributes, by using other PageSetup properties, such as LeftMargin, RightMargin, and so on.
To programmatically change the page orientation of all the sheets in the active workbook, use the steps in the previous example:
- Start Excel.
- Enter some data in three worksheets.
- Press ALT+F11 to start the Visual Basic Editor.
- On the Insert menu, click Module.
- Type the following code in the module sheet:
Sub SetAttributes()
For Each xWorksheet In ActiveWorkbook.Worksheets
xWorksheet.PageSetup.Orientation = _
Worksheets("Sheet1").PageSetup.Orientation
Next xWorksheet
End Sub
- Press ALT+F11 to switch to Excel.
- Select Sheet1.
- On the File menu, click Page Setup.
- On the Page tab, under Orientation, click Landscape, and then click OK.
- On the Tools menu, point to Macro, and then click Macros.
- Click SetAttributes, and then click Run.
All three worksheets show landscape orientation in Print Preview.
To programmatically change the page setup attributes to all pages in the active workbook based upon the page setup attributes of another open workbook, use the steps in the following example: NOTE: This is a continuation of the following example.
- On the File menu, click New.
- Click Workbook, and then click OK.
- Enter data into all of the worksheets in the new workbook.
- Press ALT+F11 to start the Visual Basic editor.
- On the Insert menu, click Module.
- Enter the following code into the module sheet:
Sub SetWorkbookAttributes()
For Each xWorksheet In ActiveWorkbook.Worksheets
xWorksheet.PageSetup.Orientation = _
ThisWorkbook.Worksheets("Sheet1").PageSetup.Orientation
Next xWorksheet
End Sub
- Press ALT+F11 to switch back to Excel.
- On the Tools menu, point to Macro, and then click Macros.
- Click SetWorkbookAttributes, and then click Run.
The page setup orientation is the same as that of sheet 1 in the first workbook.
If you want to change additional page setup properties for worksheets, you
can add additional lines within the For Each...Next statement in each Sub
procedure. The lines should be identical to the example lines provided
here, except that the property (Orientation) can be changed as appropriate
(CenterFooter, PaperSize, and so on).
REFERENCESFor more information about the PageSetup property, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type pagesetup property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Modification Type: | Major | Last Reviewed: | 10/28/2003 |
---|
Keywords: | kbdtacode kbhowto kbProgramming kbualink97 KB213257 |
---|
|