WD: Word: Macro to Print Style Name Next to Each Paragraph

Last reviewed: January 30, 1998
Article ID: Q81733
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

SUMMARY

In Microsoft Word, you can display the style names used in a document as a view option only. There is no built-in feature that inserts the style name of each paragraph next to that paragraph and print out that information.

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/supportnet/refguide/

Word has a Style Area Width option that opens a style name area on the left side of a document window to display style names. This option is for on- screen viewing only. The style names do not appear in print preview, and they do not print. To display the name of each style used in a document for display purposes only, use the appropriate method for your version of Word.

Word for Windows Version 6.x

  1. From the Tools menu, choose Options.

  2. Select the View tab, and type a value for the Style Area Width.

Word for Windows Version 2.x

  1. From the Tools menu, choose Options.

  2. From the list of Categories, select View, and type a value for the Style Area Width.

Word for Windows Version 1.x

  1. From the View menu, choose Preferences.

  2. Type a measurement for the Style Width option.

If you want to print the style name for each paragraph, use the following macro to insert the name of each style next to each paragraph in the current document.

Word for Windows Version 6.x

Word for the Macintosh 6.0, 6.0.1

Sub MAIN
 StartOfDocument
 Insert StyleName$() + ">> "
 EditFind "^p", .Direction = 0            'Searches for next paragraph
 CharRight
 While EditFindFound() And Not AtEndOfDocument()
         Insert StyleName$() + ">> "      'Inserts the Stylename and >>
         EditFind "^p", .Direction = 0    'Finds next Para
         CharRight
 Wend
End Sub

Word for Windows Version 2.x

Sub MAIN
 EndOfDocument
 Insert " "      'Error trap in case no text in last paragraph.
 num = CountStyles()          'Counts the number of current styles.
 For x = 1 To num
 StartOfDocument
 Style$ = StyleName$(x)           'Finds the name of the Style number.
 EditFindStyle .Style =  Style$   'Sets the search up for the style.
 EditFind "", .Direction = 2      'Searches for any occurrence of style.
 While EditFindFound()
        CharLeft
        Insert Style$ + ">> "          'Inserts the Stylename and >>.
        EditFind "", .Direction = 2    'Finds next Para with the stylename.
 Wend
 Next x     'goes to the next style
 EndOfDocument
 EditClear -1   'Removes space inserted to avoid endless loop.
End Sub

Word for Windows Version 1.x

Sub MAIN
 EndOfDocument
 Insert " "      'Error trap in case no text in last paragraph.
 num = CountStyles()          'Counts the number of current styles.
 For x = 1 To num
 StartOfDocument
 Style$ = StyleName$(x)       'Finds the name of the Style number.
 EditSearch .Search = "^y " + Style$, .Direction = 2  'Searches for style.

 While EditSearchFound()
         CharLeft
         Insert Style$ + ">> "          'Inserts the Stylename and >>.
         EditSearch .Search = "^y " + Style$, .Direction = 2  'Finds next.
 Wend
 Next x     'Goes to the next style.
 EndOfDocument
 EditClear -1   'Removes space inserted to avoid endless loop.
End Sub

REFERENCES

"Microsoft Word for Windows User's Guide," version 2.0, page 729


Additional query words: winword2
Keywords : kbmacroexample winword word6 kbcode kbmacro kbprg
Version : MACINTOSH:6.0,6.0.1,6.0.1a,;WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a- CD,2.0b,2.0c,6.0,6.0a,6.0c
Platform : MACINTOSH WINDOWS
Issue type : kbhowto kbinfo


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