Greg,
No, it definitely needs to be in macro format, since the action is going to
be part of a larger macro.
Thanks!
> Nexan,
>
[quoted text clipped - 6 lines]
>
> If you still want a macro, post back.
Graham Mayor - 06 Apr 2005 16:19 GMT
In that case - as Greg has just told me he is going to a meeting -
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
'**********************
.Text = "text" 'put your searched text here
.Replacement.Text = "^&"
.Replacement.Font.Underline = True
.Replacement.Font.Bold = True
'**********************
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
Selection.Find.Execute replace:=wdReplaceAll

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Greg,
>
[quoted text clipped - 13 lines]
>>
>> If you still want a macro, post back.
Greg - 06 Apr 2005 16:36 GMT
It was a short meeting. A rare thing around here :-)
Nexan - 06 Apr 2005 17:01 GMT
That worked perfectly. Thanks!
> In that case - as Greg has just told me he is going to a meeting -
>
[quoted text clipped - 36 lines]
> >>
> >> If you still want a macro, post back.
Greg - 06 Apr 2005 16:27 GMT
Nexan,
Something like:
Public Sub BasicFindReplaceWithVBA()
Dim rngstory As Word.Range
Dim findText As String
Dim replacementText As String
Dim Response As VbMsgBoxResult
findText = "Your String"
replacementText = "^&"
' 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
SearchAndAlterTextInStory rngstory, findText, replacementText
' Get next linked story (if any)
Set rngstory = rngstory.NextStoryRange
Loop Until rngstory Is Nothing
Next
End Sub
Public Sub SearchAndAlterTextInStory(ByVal rngstory As Word.Range, _
ByVal strSearch As String, ByVal strReplace As String)
ResetFRParameters
'This routine supplied by Peter Hewett
Do Until (rngstory Is Nothing)
With rngstory.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = strSearch
With .Replacement
.Text = strReplace
.Font.Bold = True
.Font.Underline = wdUnderlineSingle
End With
.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
Sub ResetFRParameters()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
End Sub