How to print list of all existing styles

G

Greg Maxey

Shimon,

Maybe something like:

Sub DisplayStyleExample()

Dim oDoc As Document
Dim myStyle As Style

Set oDoc = ActiveDocument
For Each myStyle In oDoc.Styles
Selection.Style = myStyle
Selection.Text = myStyle.NameLocal
Selection.Collapse Direction:=wdCollapseEnd
Selection.TypeText Text:=vbCr
Selection.Style = "Normal"
Next myStyle

End Sub
 
S

Shimon

Hi All,
I remember seeing a macro that runs through all styles and prints a line in
each with the style name next to it.
I think it was written in WordBasic and I tried it in Word 2000 and it
didn't work.
Do any of you know have such a macro?
Thanks,
Shimon
 
S

Shimon

Hi Greg,
Thanks for the response, and for the ideas. I'll try to fix it up some, and
send it back.
Have a great day,
Shimon
 
S

Shimon

Hello Greg,
I just opened your code to try to change it a little and I realized that
this macro shows all the styles existing in a specific document.
What I wanted is a macro that runs through all the "possible" styles for the
document, which inckudes any styles in all templates attached to the
document.
Thanks,
Shimon
 
S

Shimon

Hi Again,
Sorry for being so hastefull. I wrote the previous post after reading the
code, but before trying it out. It works beautifully. Thank you so much.
Have a good day and success in all your endeavors,
Shimon
 
G

Greg Maxey

When I run this code it displays every style in Normal.dot which is attached
to the blank document that I used to create the code.
 
J

Jean-Guy Marcil

Shimon was telling us:
Shimon nous racontait que :
Hello Greg,
I just opened your code to try to change it a little and I realized
that this macro shows all the styles existing in a specific document.
What I wanted is a macro that runs through all the "possible" styles
for the document, which inckudes any styles in all templates attached
to the document.

A document can only have one attached template.

Unless the "Update styles from template" option is active (Tools > Templates
and Add-ins), the styles in the template have nothing to do with the styles
in the document (Of course, when the document is created form the template,
the document has exactly the same styles. But, if you later change the
styles in the templates, or add/delete/modify the styles in the document,
there will be a discrepancy in the document style list when compared to the
template. At that point, the styles in the template are not "available" to
the document unless you do something to bring them in).

So it seems to me that Greg's code will show you all the available styles in
a target document.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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