WD: Macros to Find Automatic (Soft) Page Breaks

Last reviewed: February 18, 1998
Article ID: Q96375
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Word for the Macintosh, versions 6.0, 6.0.1

SUMMARY

To search for "hard" (manually inserted) page breaks and section breaks in a Word, click Find on the Edit menu, and type ^m (^d in versions of Word prior to 6.x) in the Find What box.

There is no search character to locate "soft" (automatic) page breaks within a document. The macro examples in the "More Information" section of this article can be used to locate automatic page breaks.

MORE INFORMATION

Soft page breaks are automatically inserted by Word when the end of the document page is reached. Any new text is automatically pushed to the next page. A soft page break also occurs before a paragraph formatted with the Page Break Before option selected in the Paragraph dialog box.

You can insert hard page breaks by pressing CTRL+ENTER(In Word for the Macintosh, option+return) or selecting the Page Break option button in the Insert Break dialog box.

The following macro examples examine the page breaks in a document and determine whether or not they are soft page breaks. The macro examples retrieve the total number of pages in the document and then move to each page break successively. By moving the selection to the left one character, the macro examples determine if the new selection is text or a hard page break. Document text has a character code greater than 31, and a hard page break is character number 12 or 14.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

   Sub MAIN
      EditBookmark .Name = "WhereYouWere"
      StartOfDocument
      ToolsRepaginate
      NumPages = SelInfo(4)
      p = 2
      While p <= NumPages
         p$ = Str$(p)
         EditGoTo .Destination = p$
         CharLeft 1
         CurSel$ = Selection$()
         a = Asc(CurSel$)
         If a <> 12 And a <> 14 Or a > 31 Then
            MsgBox "An automatic page break precedes page " + p$ + "."
         End If
         p = p + 1
      Wend
      EditGoTo .Destination = "WhereYouWere"
      EditBookmark .Name = "WhereYouWere", .Delete
   End Sub

To replace soft page breaks with hard page breaks throughout your document, replace the following macro line

  MsgBox "An automatic page break precedes page" + p$ + "."

with the following two lines:

  If SelInfo(13) <> - 1 Then CharRight 1
  InsertBreak .Type=0

NOTE: The first of these two lines checks to see if the insertion point is in a table.

WordBasic - Word 2.x

   Sub MAIN
      InsertBookmark .Name = "WhereYouWere"
      StartOfDocument
      ToolsRepaginateNow
      NumPages = SelInfo(4)
      p = 2
      While p <= NumPages
         p$ = Str$(p)
         EditGoTo .Destination = p$
         CharLeft 1, 1
         CurSel$ = Selection$()
         a = Asc(CurSel$)
         If a <> 12 And a <> 14 Or a > 31 Then
            MsgBox "An automatic page break precedes page" + p$ + "."
         End If
         p = p + 1
      Wend
      EditGoTo .Destination = "WhereYouWere"
      InsertBookmark .Name = "WhereYouWere", .Delete
   End Sub

To replace soft page breaks with hard page breaks throughout your document, change the following macro line

   MsgBox "An automatic page break precedes page" + p$ + "."

to the following:

   InsertBreak .Type=0

REFERENCES

"Microsoft Word for Windows User's Guide," version 2.0, pages 260-266

"Using WordBasic" by WexTech Systems, Inc. and Microsoft Corporation, Microsoft Press, 1992.


Additional query words: pagination manual
Keywords : kbmacroexample macword macword5 winword winword2 word6 word7 word95 wordnt macword6 kbprint
Version : WINDOWS:2.0,2.0a,2.0b,2.0c,6.0,6.0a,6.0c;MACINTOSH:3.0,3.01,3.02,4.0,5.0,5.1,5.1a,6.0,6.0.1,6.0.1a
Platform : MACINTOSH Win95 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 18, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.