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 Template

For 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:
  1. Press SHIFT and then click each worksheet tab in the workbook that you want to affect.
  2. On the File menu, click Page Setup.
  3. 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 Macro

Microsoft 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:
  1. Start Excel.
  2. Enter some data in three worksheets.
  3. Press ALT+F11 to start the Visual Basic Editor.
  4. On the Insert menu, click Module.
  5. 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
    						
  6. Press ALT+F11 to switch to Excel.
  7. Select Sheet1.
  8. On the File menu, click Page Setup.
  9. On the Page tab, under Orientation, click Landscape, and then click OK.
  10. On the Tools menu, point to Macro, and then click Macros.
  11. 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.
  1. On the File menu, click New.
  2. Click Workbook, and then click OK.
  3. Enter data into all of the worksheets in the new workbook.
  4. Press ALT+F11 to start the Visual Basic editor.
  5. On the Insert menu, click Module.
  6. 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
    						
  7. Press ALT+F11 to switch back to Excel.
  8. On the Tools menu, point to Macro, and then click Macros.
  9. 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).

REFERENCES

For 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:MajorLast Reviewed:10/28/2003
Keywords:kbdtacode kbhowto kbProgramming kbualink97 KB213257