XL: Strange Value for PageSetup.FirstPageNumber

Last reviewed: February 3, 1998
Article ID: Q117411

The information in this article applies to:
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel 97 for Windows
  • Microsoft Excel 98 Macintosh Edition

SYMPTOMS

In Microsoft Excel, if you use a Microsoft Visual Basic for Applications procedure to get the FirstPageNumber property of a sheet, you may receive the value -4105.

MORE INFORMATION

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

In Microsoft Excel, to set the first page number of a sheet, do either of the following:

To Manually Set the First Page Number

  1. On the File menu, click Page Setup.

  2. Click the Page tab.

  3. In the First Page Number edit box, enter a starting page number (a positive integer from 1 to 32767) or enter "Auto" (without the quotation marks) to have Microsoft Excel automatically determine the starting page number.

  4. Click OK to accept the change.

To Set the First Page Number Using Visual Basic Code

   ActiveSheet.PageSetup.FirstPageNumber = <value>

where <value> is an integer from -32765 to 32767, or the word "xlAutomatic" (without the quotation marks).

You can also check and store the FirstPageNumber property of a worksheet in a variable by using this code:

   <variable> = ActiveSheet.PageSetup.FirstPageNumber

The value returned to <variable> by this statement may be either:

   Value                     Indicates
   -----------------------------------------------------------------------
   A positive integer        User-defined starting page number

   -4105                     Automatically determined starting page number

Note that -4105 is the value of the built-in constant "xlAutomatic"; when the worksheet has "Auto" in its First Page Number edit box, this is the value actually stored in the FirstPageNumber property.

You can check whether a worksheet is using automatic page numbering by using a line of code such as this:

   If ActiveSheet.PageSetup.FirstPageNumber = xlAutomatic Then
       <action>
   End If

The following Visual Basic code example illustrates one possible use of this procedure.

Sample Visual Basic Procedure

The following sample Sub procedure loops through all of the worksheets in the active workbook, reporting the first page number assigned to each worksheet. If the worksheet is using automatic page numbering, the Sub will report this.

   Option Explicit

   Sub CheckFirstPageNumbers()

       ' Dimension variables.
       Dim MsgString As String, xWorksheet As Variant

       ' Iterate through the loop once for each worksheet in the active
       ' workbook.
       For Each xWorksheet In ActiveWorkbook.Worksheets

           ' Begin making the string to be shown in the message box below.
           MsgString = "The worksheet '" & xWorksheet.Name & "'"

           ' If the worksheet is using automatic page numbering...
           If xWorksheet.PageSetup.FirstPageNumber = xlAutomatic Then

               ' ...complete the message string accordingly.
               MsgString = MsgString & " is using automatic page " & _
                   "numbering."

           ' Otherwise...
           Else

               ' ...complete the message string accordingly.
               MsgString = MsgString & " starts its page numbers at " & _
                   xWorksheet.PageSetup.FirstPageNumber

           End If

           ' Show the message.
           MsgBox MsgString
       Next xWorksheet                       ' Loop until finished.
   End Sub


Additional query words: 5.00 5.00a 5.00c 7.00 XL98 XL97 XL7 XL5
Keywords : kbcode kbprg PgmOthr SynFnc
Version : WINDOWS:5.0,5.0c,7.0,97; MACINTOSH:5.0,5.0a,98
Platform : MACINTOSH WINDOWS
Issue type : kbprb
Solution Type : kbworkaround


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.