A way to reveal styles?

C

Carol NS

Hi there. I need to print out a very long document and
then go through it and put the names of all the styles
used next to the paragraphs. I don't suppose there is
anyway I could just tell the computer to print all the
style names?
Thanks for any advice.
Carol NS
 
D

Doug Robbins - Word MVP

The following macro will insert the style at the end of each paragraph.

Dim apara As Paragraph, prange As Range
For Each apara In ActiveDocument.Paragraphs
Set prange = apara.Range
prange.End = prange.End - 1
prange.InsertAfter " - " & apara.Style
Next apara


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Dayo Mitchell

Alternatively, when you go to print, the print dialog box should have a
Print: or Print What? Dropdown menu, which you can set to styles, and it
will print a list of styles.

DM
 
C

Carol NS

Mr Robbins, thank you for the macro. Just one thing: it's
tells me when I run it: "Run time error 5251: not a valid
action for the end of a row".
In the New Macros (Code) window, the line
prange.InsertAfter " - " & apara.Style
is highlighted.
I apologise if I'm doing something obviously wrong here -
it's the first time I've done one of these. (I used
the "What do I do with macros other users send me"
article).
Carol NS
 
D

Doug Robbins - Word MVP

That would be because you have tables in the document. The following
modified code will skip the tables:

Dim apara As Paragraph, prange As range
For Each apara In ActiveDocument.Paragraphs
Set prange = apara.range
prange.End = prange.End - 1
If Not prange.Information(wdWithInTable) Then
prange.InsertAfter " - " & apara.Style
End If
Next apara

or, the following will just ignore that error message and insert the style
after the paragraphs in the table as well:

Dim apara As Paragraph, prange As range
On Error Resume Next
For Each apara In ActiveDocument.Paragraphs
Set prange = apara.range
prange.End = prange.End - 1
prange.InsertAfter " - " & apara.Style
Next apara


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Carol NS

Problem solved. Thank you VERY much.
-----Original Message-----
That would be because you have tables in the document. The following
modified code will skip the tables:

Dim apara As Paragraph, prange As range
For Each apara In ActiveDocument.Paragraphs
Set prange = apara.range
prange.End = prange.End - 1
If Not prange.Information(wdWithInTable) Then
prange.InsertAfter " - " & apara.Style
End If
Next apara

or, the following will just ignore that error message and insert the style
after the paragraphs in the table as well:

Dim apara As Paragraph, prange As range
On Error Resume Next
For Each apara In ActiveDocument.Paragraphs
Set prange = apara.range
prange.End = prange.End - 1
prange.InsertAfter " - " & apara.Style
Next apara


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top