Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2005

Tip: Looking for answers? Try searching our database.

Controlling/Replacing Avaiable Styles

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ML - 15 Feb 2005 17:36 GMT
We have a document template we are developing that has two sets of styles,
one for numbered headers/section and one for unnumbered.

Is there anyway that we can control which styles are shown to the user based
on say a userform selection where the user picks if they want the numbered
or unnumbered version?

Secondly, is there anyway to replace all the styles throughout a document
from one type to another, so that a macro could possibly be used to change
all the styles from the numbered version to the unnumbered version?
Jonathan West - 15 Feb 2005 17:50 GMT
> We have a document template we are developing that has two sets of styles,
> one for numbered headers/section and one for unnumbered.
>
> Is there anyway that we can control which styles are shown to the user
> based on say a userform selection where the user picks if they want the
> numbered or unnumbered version?

This depends on which version of Word you are using. If you are using Word
2003, then this is possible, take a look at the following article. The stuff
on restricted styles is towards the end.

Creating Custom Toolbars for Templates
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=262

> Secondly, is there anyway to replace all the styles throughout a document
> from one type to another, so that a macro could possibly be used to change
> all the styles from the numbered version to the unnumbered version?

If you have another template containing the other form of the styles, then
you can use the OrganizerCopy method to copy styles across.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup

ML - 15 Feb 2005 18:21 GMT
This needs to work for Word 2000 and higher.

Is there possibly some way in a macro to replace one style with another
easily?

>> 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.
Jonathan West - 15 Feb 2005 18:28 GMT
> 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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.