XL: How to Set Page Setup Attributes for More Than One Sheet

Last reviewed: February 3, 1998
Article ID: Q154663
The information in this article applies to:
  • Microsoft Excel 98 Macintosh Edition
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for Windows, versions 5.0, 5.0c

SUMMARY

By default, page setup attributes, such as margins, sheet orientation, and print titles, are set individually (on a worksheet-by-worksheet basis). However, you can set some of these attributes globally by using any of the following methods:

  • Use a template.
  • Select multiple worksheets and apply the attributes to that group of worksheets.
  • Use a macro to set attributes for all sheets in the workbook.

The "More Information" section of this article discusses these options in more detail.

MORE INFORMATION

Method 1: Use a Template

For information about using templates to set page orientation, click the Index tab in Help, and type:

      page setup, storing settings in a template

Method 2: Change a Group of Worksheets

Select multiple worksheets and apply the attributes to that group of worksheets. To select multiple worksheets, press and hold the SHIFT key, and click the sheets you want to select.

For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q125640
   TITLE     : XL: Can't Set Print Area or Print Titles

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 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 needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

   http://www.microsoft.com/support/supportnet/refguide/default.asp

Modify the page setup attributes with a macro. The sample macros in this article demonstrate how to change page orientation in the active workbook and in an open workbook that is not the active workbook.

NOTE: These macros use the Orientation property of the PageSetup object. To modify other page setup attributes, use other PageSetup properties, such as LeftMargin, RightMargin, and so on.

Macros to Change Page Orientation:

This macro sets page orientation for all sheets in the active workbook to be the same as the first sheet in the workbook.

   Sub SetAttributes()
      For Each xWorksheet In ActiveWorkbook.Worksheets
         xWorksheet.PageSetup.Orientation = _
            Worksheets("Sheet1").PageSetup.Orientation
      Next xWorksheet
   End Sub

   ' The workbook containing the following macro also includes a
   ' worksheet called Sheet1, which is the source of the PageSetup
   ' information that you want to use to format the worksheets in
   ' another workbook.

   ' Before you run this macro, make sure that the second workbook
   ' is active.

   Sub SetWorkbookAttributes()
      For Each xWorksheet In ActiveWorkbook.Worksheets
         xWorksheet.PageSetup.Orientation = _
            ThisWorkbook.Worksheets("Sheet1").PageSetup.Orientation
      Next xWorksheet
   End Sub

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

For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119157
   TITLE     : XL: Macro to Change Page Orientation in Group Mode Incorrect

REFERENCES

"Visual Basic User's Guide," version 5.0, pages 145-146


Additional query words: 7.00 8.00 XL98 XL97 XL7 XL5
Keywords : kbcode kbprg kbualink97 PgmHowto
Version : WINDOWS:5.0,7.0,97; MACINTOSH:5.0,98
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


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: February 3, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.