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 / September 2005

Tip: Looking for answers? Try searching our database.

find and replace field codes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
frogman - 13 Sep 2005 21:01 GMT
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
Klaus Linke - 13 Sep 2005 23:24 GMT
Field braces aren't really the same characters as the curly braces { }.
Use ^d for them, or ^19 for the opening brace and ^21 for the closing brace.

Greetings,
Klaus

>i have looked at several different solutions but none seem to
> work for me.
[quoted text clipped - 60 lines]
>
> when i run the code nothing happens
 
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.