Dave
Tue May 03 07:45:21 CDT 2005
Hi Donna,
You could do something with the following line:
SearchAndReplaceInStory rngStory, "Location", "New Location"
by changing it to
SearchAndReplaceInStory rngStory, "Location", InputBox("Enter the
location.", "Location", "New Location")
HTH,
Dave
"Donna_82" <Donna82@discussions.microsoft.com> wrote in message
news:0D0510A8-8174-495A-8472-BF1E298ACD3D@microsoft.com...
> Hi Dave,
>
> I'm sorry but I'm very new to programming in Word. Could you tell me
where
> that would fit into the code I'm using now? The code is currently as
follows:
>
> Public Sub SREntireDoc()
> 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, "Location", "New Location"
>
> ' Get next linked story (if any)
> Set rngStory = rngStory.NextStoryRange
> Loop Until rngStory Is Nothing
> Next
> 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
> .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
>
> This code came from a link I found through this site.
> Your help is very much appreciated!
>
> Donna
>
>
> "Dave Lett" wrote:
>
> > Hi Donna,
> >
> > You can try using the InputBox function, as in the following:
> >
> > With Selection
> > .HomeKey Unit:=wdStory
> > With .Find
> > .ClearFormatting
> > .Text = "location"
> > .Execute
> > End With
> > .Text = InputBox("Enter the location.", "Location", "New Location")
> > End With
> >
> > HTH,
> > Dave
> >
> > "Donna_82" <Donna_82@discussions.microsoft.com> wrote in message
> > news:EDF621E7-C98F-4567-8B1C-A2525C6513E5@microsoft.com...
> > > Hi there,
> > >
> > > You'll have to forgive me because I'm sure there is an incredibly
simple
> > > answer to my question. However, I can't seem to figure it out.
> > >
> > > I'm using the code found at this link:
> > >
> > >
http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm
> > >
> > > to replace the words "location"with the specifc location (i.e.
> > "Vancouver").
> > > But instead of replacing with a specific word everytime I need to
replace
> > > with a word which is different everytime and entered by the user (the
> > > location needs to be entered in each report separately). I'd rather
not
> > have
> > > to go in to change the code for each report as this is inefficient.
> > >
> > > Please help!
> > >
> > > Thanks in advance.
> >
> >
> >