D
Dawn Rhoads
With the help of past posts on this newsgroup (thank you!) I am working on a
macro that will find all text set in a particular style, and then delete it.
(BTW, I am still just a record-a-macro person, but I can sometimes cobble
together other people's code to do more.)
The problem I am having is that if any one of the three styles is not
present in the document, the macro fails on the "selection.find.style" line
of code and tells me it can't find the requested member. I guess I'm looking
for a way to make the macro "skip" the section when there is no such style in
the document?
I found "error handling" code from other newsgroup posts that I stuck in
that seems like it might be the right idea, but right now, it just pops up a
message box saying what the problem is. I would like to make sure if some
other error besides the missing style comes up, that the error will still
show up, since goodness knows what other problems I might run into later!
Any thoughts are appreciated!
On Error GoTo ErrHandler
With Selection.Find
.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Hidden")
Text = ""
With .Replacement
.ClearFormatting
.Text = ""
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
.Execute Replace:=wdReplaceAll
End With
With Selection.Find
.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Hidden Text Instruction")
Text = ""
With .Replacement
.ClearFormatting
.Text = ""
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
.Execute Replace:=wdReplaceAll
End With
With Selection.Find
.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Hidden Text Instruction
Char")
Text = ""
With .Replacement
.ClearFormatting
.Text = ""
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
.Execute Replace:=wdReplaceAll
End With
Exit Sub
ErrHandler:
If Err.Number = 5941 Then
MsgBox "Requested style is not in the document!"
Else
MsgBox ("Error " & CStr(Err.Number) & ": " & Error)
End If
End Sub
macro that will find all text set in a particular style, and then delete it.
(BTW, I am still just a record-a-macro person, but I can sometimes cobble
together other people's code to do more.)
The problem I am having is that if any one of the three styles is not
present in the document, the macro fails on the "selection.find.style" line
of code and tells me it can't find the requested member. I guess I'm looking
for a way to make the macro "skip" the section when there is no such style in
the document?
I found "error handling" code from other newsgroup posts that I stuck in
that seems like it might be the right idea, but right now, it just pops up a
message box saying what the problem is. I would like to make sure if some
other error besides the missing style comes up, that the error will still
show up, since goodness knows what other problems I might run into later!
Any thoughts are appreciated!
On Error GoTo ErrHandler
With Selection.Find
.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Hidden")
Text = ""
With .Replacement
.ClearFormatting
.Text = ""
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
.Execute Replace:=wdReplaceAll
End With
With Selection.Find
.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Hidden Text Instruction")
Text = ""
With .Replacement
.ClearFormatting
.Text = ""
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
.Execute Replace:=wdReplaceAll
End With
With Selection.Find
.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Hidden Text Instruction
Char")
Text = ""
With .Replacement
.ClearFormatting
.Text = ""
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
.Execute Replace:=wdReplaceAll
End With
Exit Sub
ErrHandler:
If Err.Number = 5941 Then
MsgBox "Requested style is not in the document!"
Else
MsgBox ("Error " & CStr(Err.Number) & ": " & Error)
End If
End Sub