This needs to work for Word 2000 and higher.
Is there possibly some way in a macro to replace one style with another
easily?
> This needs to work for Word 2000 and higher.
Then I'm afraid you're stuck, at least in terms of preventing access to
unauthorised styles. The best you can manage is to make it easy for users to
use the authorised styles. The same article I referred you to before will
still help.
> Is there possibly some way in a macro to replace one style with another
> easily?
You can use the Find object for this. Have the Text and Replacement.Text
properties both set to empty strings, the Format property set to True, the
.Style property set to the old style and the Replacement.Style property set
to the new style.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
>>> We have a document template we are developing that has two sets of
>>> styles, one for numbered headers/section and one for unnumbered.
[quoted text clipped - 17 lines]
>> If you have another template containing the other form of the styles,
>> then you can use the OrganizerCopy method to copy styles across.
ML - 15 Feb 2005 18:38 GMT
Thanks again.
> You can use the Find object for this. Have the Text and Replacement.Text
> properties both set to empty strings, the Format property set to True, the
> .Style property set to the old style and the Replacement.Style property
> set to the new style.
So doing is it possible somehow loop through an entire document and reset
the styles on every piece of text? I guess basically I need to do a find
and replace automatically on the entire document, replacing the old style
with the new style.
>> This needs to work for Word 2000 and higher.
>
[quoted text clipped - 32 lines]
>>> If you have another template containing the other form of the styles,
>>> then you can use the OrganizerCopy method to copy styles across.
Jonathan West - 15 Feb 2005 18:42 GMT
> Thanks again.
>
[quoted text clipped - 7 lines]
> and replace automatically on the entire document, replacing the old style
> with the new style.
Easier would be to do find-replace for each style, searching the entire
document

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
ML - 15 Feb 2005 18:49 GMT
Thanks. Do you happen to have a sample of code for doing such a replace on
styles?
This sounds like it should work. Both the numbered and unnumbered styles
are defined in the document so if I can do a macro that replaces A->B then
this should work out.
I have for example "Heading 1 (UN)" and "Heading 1 (N)" and based on the
userform selection want to replace one with the other.
>> Thanks again.
>>
[quoted text clipped - 10 lines]
> Easier would be to do find-replace for each style, searching the entire
> document
ML - 15 Feb 2005 19:06 GMT
I think I have it Jonathan.
Sub ReplaceStyles()
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.Find.ParagraphFormat.Borders.Shadow = False
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("Heading 1
Plain" _
)
Selection.Find.Replacement.ParagraphFormat.Borders.Shadow = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
>> Thanks again.
>>
[quoted text clipped - 10 lines]
> Easier would be to do find-replace for each style, searching the entire
> document
ML - 15 Feb 2005 19:13 GMT
Bit of a problem. When I recorded the macro the replace worked, but when I
play the macro back to do it via the macro it doesn't seem to do the
replace, the old style remains in place unchanged.
Any ideas?
>I think I have it Jonathan.
>
[quoted text clipped - 37 lines]
>> Easier would be to do find-replace for each style, searching the entire
>> document
Klaus Linke - 10 Mar 2005 22:55 GMT
> Bit of a problem. When I recorded the macro the replace worked, but when I
> play the macro back to do it via the macro it doesn't seem to do the
> replace, the old style remains in place unchanged.
>
> Any ideas?
Delete the line
Selection.Find.ParagraphFormat.Borders.Shadow = False
In Word2000 (perhaps even 97... not sure) you can set styles to .Hidden=True, and they won't show in the interface.
Since that's an undocumented feature (as far as I know), that might be risky though... especially for others that have to work with your documents and don't know what you did.
And it's not the same as the feature used by Word2003 (.Visibilityúlse).
Regards,
Klaus