Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adjusting Style in a Word Document 1

Status
Not open for further replies.

colinmitton

Technical User
Feb 24, 2005
190
GB
I'm trying to create a macro to adjust some styles in a word 2003 document. I have succesfully created macro that adjusts a single or multiple style(s) in a document as long as they are there. If the Style is not there it crashes and goes in to debug mode.

So to combate this I'm trying to set it up to check if the style exists and if it does adjust the style if not the skip on to the next style.

I looked around a few sites and tried these two solutions but both fail, my idea being setup a macro to change each (individual) style to how we need it, then to have a macro to check for all style and if that style exists to run the macro to change that style. I used the following two ways but both kept giving me errors.

Sub checkstyle1()
If Style.Exists("Style1") = True Then
Application.Run MacroName:="Normal.NewMacros.changestyle1"
End If
End Sub

And

Sub checkstyle1()
If Style("Style1").InUse = True Then
Application.Run MacroName:="Normal.NewMacros.changestyle1"
End If
End Sub

I'm sure theres an easier way or I'm missing something really simple!

Thanks in Advance.
 
This seems odd.

If you need to change the structure of style you should be changing it in the template that holds it.

BTW, please try and be more informative.

" tried these two solutions but both fail"

" both kept giving me errors."

"fail"????

"errors"????

WHAT errors? Is it failing because there is something wrong in Sub changestyle1?

faq219-2884

Gerry
My paintings and sculpture
 
Hi Colin,

Neither the 'Style' object nor the 'Styles' collection supports the 'Exists' method.

Try something like:
Code:
Sub CheckStyles()
Dim sStyle As Style
For Each sStyle In ActiveDocument.Styles
  If sStyle.NameLocal = "Style1" Then
    Application.Run MacroName:="Normal.NewMacros.changestyle1"
  End If
Next
End Sub
Cheers

[MS MVP - Word]
 
Macropod,

Thanks very much for that it works a dream!!! Only have to do another 48 more styles :)))

Fumei,

Sorry for the lack of detail, I had to rush out as I had another issue at work and was planning more details this morning! the two solutions I tried were the code that was entered at the bottom of posting.

Thanks Folks...
 
Hi Colin,

A simple 'Select Case' approach would suffice for that - or 48 consecutive If tests ...

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top