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 / April 2007

Tip: Looking for answers? Try searching our database.

Find and reset particular styles

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
automandc - 11 Apr 2007 01:34 GMT
[Word 2003]:  I am trying to figure out a way to programatically apply the
".font.reset" method to all text of particular document style.  Ideally I
would like to do it using the Range method of Find, but the exact syntax is
eluding me.

More detail:

I have set up a number of checkboxes to show/hide certain portions of a long
document based on styles (by modifying the ".font.hidden" property of certain
styles).  However, I am finding that the document can get out of whack, where
certain sections seem to have the "hidden" property applied even though it is
not default for the style (probably because I am also using the bookmark
method to show/hide certain contiguous portions of the document).  I want an
easy way to quickly reset text in particular styles to the style default.  
The non programatic way would be to use the Style pull-down and "Select all X
instances", then click the style name and select "Reapply Style" from the
dialog box that comes up.

Thanks.
Jay Freedman - 11 Apr 2007 03:32 GMT
>[Word 2003]:  I am trying to figure out a way to programatically apply the
>".font.reset" method to all text of particular document style.  Ideally I
[quoted text clipped - 15 lines]
>
>Thanks.

This should show the way...

Sub ResetStyles()
   Dim StyleList As Variant
   Dim i As Long
   Dim oRg As Range
   
   StyleList = Split("Normal,Heading 1,Heading 2", ",")
   
   For i = 0 To UBound(StyleList)
   
       Set oRg = ActiveDocument.Range
       
       With oRg.Find
           .ClearFormatting
           .Text = ""
           .Style = ActiveDocument.Styles(StyleList(i))
           .Format = True
           .Forward = True
           .Wrap = wdFindStop
           .MatchWildcards = False
           
           Do While .Execute
               oRg.Font.Reset
           Loop
       End With
   
   Next
End Sub

Within the first pair of quotes in the Split function, enter a
comma-delimited list of all the style names that you want to reset.
The For loop will cycle through the listed styles, and the Do loop
will reset all occurrences of each style in the main body of the
document.

If you also need to reset styles in textboxes, headers/footers,
footnotes/endnotes, etc. then you need more stuff in your macro.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
automandc - 11 Apr 2007 03:44 GMT
Perfect, thanks!

> >[Word 2003]:  I am trying to figure out a way to programatically apply the
> >".font.reset" method to all text of particular document style.  Ideally I
[quoted text clipped - 61 lines]
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.
Klaus Linke - 11 Apr 2007 04:57 GMT
... and you wouldn't really need a macro: Replacing with the "Default
Paragraph Font" achieves exactly the same result.

Regards,
Klaus

> Perfect, thanks!
>
[quoted text clipped - 74 lines]
>> Email cannot be acknowledged; please post all follow-ups to the
>> newsgroup so all may benefit.
 
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.