Changing Styles

V

Vince

This is crazy. I am trying to change the style "COOL" in the document to
another style called "NOTSOCOOL". I wrote this:

With ActiveDocument.Range.Find
.Style = "COOL"
.ClearFormatting
.MatchWildcards = False

With .Replacement
.Style = "NOTSOCOOL"
End With

.Execute Replace:=wdReplaceAll
End With


Doesn't work! I am positive that nothing extra is set, the same code (when
..style is removed and .text is added) finds and replaces words with no
problems. The styles definitely exist and I did a manual Find and Replace
(Edit - Find) and it works fine.

What's wrong with the code?

Thank you for your time / response

Vince
 
W

Word Heretic

G'day "Vince" <[email protected]>,

I'd structure it more like
With ActiveDocument.Range.Find
.ClearFormatting
.MatchWildcards = False
.Style = "COOL"
With .Replacement
.Style = "NOTSOCOOL"
End With

.Execute Replace:=wdReplaceAll
End With

but also, does the NOTSOCOOL style EXIST? Styles.Add "NOTSOCOOL"
first, and do an on error resume next

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Vince reckoned:
 
V

Vince

Steve,

And I spent two hours on that!!! Don't believe it!

Thanks a lot, needless to say, it works fine!

Vince
 
W

Word Heretic

G'day "Vince" <[email protected]>,

Well, I'm glad my 30 seconds was worth it then :)


Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Vince reckoned:
 

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