Find and reset particular styles

A

automandc

[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.
 
J

Jay Freedman

[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.

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
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
A

automandc

Perfect, thanks!

Jay Freedman said:
[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.

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
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
K

Klaus Linke

.... and you wouldn't really need a macro: Replacing with the "Default
Paragraph Font" achieves exactly the same result.

Regards,
Klaus



automandc said:
Perfect, thanks!

Jay Freedman said:
[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.

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
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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