F
frogman
i have looked at several different solutions but none seem to work for
me.
I want to find all field codes that are meteric and hide them then
later they will be deleted.
field code:
[{MACROBUTTON NoMacro {Quote "___" \*CharFormat}} m]
text in document:
[___ m]
the code I have is taken from:
http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm
Public Sub SREntireDoc()
ActiveWindow.View.ShowFieldCodes = True
Dim rngStory As Word.Range
' Fix the skipped blank Header/Footer problem
MakeHFValid
' Iterate through all story types in the current document
For Each rngStory In ActiveDocument.StoryRanges
' Iterate through all linked stories
Do
SearchAndReplaceInStory rngStory, "[{MACROBUTTON NoMacro
{Quote ""___"" \*CharFormat}} m]", "itworked"
' Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
ActiveWindow.View.ShowFieldCodes = False
End Sub
Public Sub SearchAndReplaceInStory(ByVal rngStory As Word.Range, ByVal
strSearch As String, ByVal strReplace As String)
Do Until (rngStory Is Nothing)
With rngStory.find
.Text = strSearch
.ClearFormatting
.Replacement.ClearFormatting
.Text = strSearch
.Replacement.Text = strReplace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
Set rngStory = rngStory.NextStoryRange
Loop
End Sub
Public Sub MakeHFValid()
Dim lngJunk As Long
' It does not matter whether we access the Headers or Footers
property.
' The critical part is accessing the stories range object
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
End Sub
when i run the code nothing happens
me.
I want to find all field codes that are meteric and hide them then
later they will be deleted.
field code:
[{MACROBUTTON NoMacro {Quote "___" \*CharFormat}} m]
text in document:
[___ m]
the code I have is taken from:
http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm
Public Sub SREntireDoc()
ActiveWindow.View.ShowFieldCodes = True
Dim rngStory As Word.Range
' Fix the skipped blank Header/Footer problem
MakeHFValid
' Iterate through all story types in the current document
For Each rngStory In ActiveDocument.StoryRanges
' Iterate through all linked stories
Do
SearchAndReplaceInStory rngStory, "[{MACROBUTTON NoMacro
{Quote ""___"" \*CharFormat}} m]", "itworked"
' Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
ActiveWindow.View.ShowFieldCodes = False
End Sub
Public Sub SearchAndReplaceInStory(ByVal rngStory As Word.Range, ByVal
strSearch As String, ByVal strReplace As String)
Do Until (rngStory Is Nothing)
With rngStory.find
.Text = strSearch
.ClearFormatting
.Replacement.ClearFormatting
.Text = strSearch
.Replacement.Text = strReplace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.Execute Replace:=wdReplaceAll
End With
Set rngStory = rngStory.NextStoryRange
Loop
End Sub
Public Sub MakeHFValid()
Dim lngJunk As Long
' It does not matter whether we access the Headers or Footers
property.
' The critical part is accessing the stories range object
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
End Sub
when i run the code nothing happens