Set font of all styles

A

arne

Using Word 2003, and I need to set the font of all styles, also Word builtin
styles to Tahoma.

Changing the normal style is only one step, and does not cover all styles,
since some styles are not not based on normal.

Something like this code (that does not work)
For each myStyle in ActiveDocument.Styles
ActiveDocument.Styles("myStyle").Font
.Name = "Tahoma"
Next myStyle
-
 
S

Shauna Kelly

Hi Arne

This code:
ActiveDocument.Styles("myStyle")
is referring to a style in the ActiveDocument called "myStyle". And I
suspect you don't have one.

You need something like this

Option Explicit

Sub MakeAllStylesFontsTahoma()

Dim myStyle As Word.Style

For Each myStyle In ActiveDocument.Styles
myStyle.Font.Name = "Tahoma"
Next myStyle

End Sub


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
A

arne

The code changes the font AND a lot other properties; indent, numberng and
...., especilly in the header styles.
Header 1 text becomes Article 1. text and so on.I am using Norwegian Word
2003, fully updated.

Any suggestions?
 
J

Jonathan West

arne said:
The code changes the font AND a lot other properties; indent, numberng and
..., especilly in the header styles.
Header 1 text becomes Article 1. text and so on.I am using Norwegian
Word 2003, fully updated.

Any suggestions?

Arne,

Read Shauna's post more carefully. I'll repeat the important bit of it
ActiveDocument.Styles("myStyle")
is referring to a style in the ActiveDocument called "myStyle"

If you want to go through all the styles in a document, you were halfway
there with this loop

For each myStyle in ActiveDocument.Styles

Next myStyle

What this does is go through the loop and assigns each style in the document
in turn to the myStyle object variable. So, if the first style in the list
os styles happens to be Normal, the first time round the loop, the myStyle
variable will refer to the Normal style. You can check this by expanding the
code above as follows

Dim i As Long
Dim myStyle As Style 'always declare your variables
For Each myStyle In ActiveDocument.Styles
i = i + 1
Debug.Print "Style " & i & " is called " & myStyle.NameLocal
Next myStyle

The complete list of styles in the document is then printed in the immediate
window.


Now, you can replace the Debug.Print code with whatever you want. You can
use If-Then or Select case statements to make different changes to different
styles depending on the name or some other characteristic.
 

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