I am advanced in Word, but new to using VBA, having watched Steph Krieger's
Webcast and read a few of your MVP articles on editing macros in VBA. I am
using Word 2003 and am having trouble with the Dim "MyText" As _____ command
in order to do the For Each.....Next command. I don't know what to define
the MyText as. The macro finds the text "Matt.", then a Hyperlink to a
spcific Bookmark in the active document is inserted. There are several
hundred instances of "Matt." in my document. If I could get help with this
step, then I will be able to create macros for the 27 other Bookmarks in my
document!
Here is my initial macro (edited) and it does work:
Option Explicit
Sub MattB()
'
' MattB Macro
' Bookmark to Matthew in TOC
'
With Selection.Find
.ClearFormatting
.Style = ActiveDocument.Styles( _
"Style Body TextBT + Bold Char")
.Text = "Matt."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="", _
SubAddress:="Matthew", ScreenTip:="", TextToDisplay:="Matt."
End Sub

Signature
Thanks, Danke sehr, Merci!
Alice
Doug Robbins - 30 Jul 2005 19:44 GMT
Hi Alice,
This is the way to do it:
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="Matt.", MatchWildcards:=False,
Wrap:=wdFindContinue, Forward:=True) = True
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:="",
_
SubAddress:="Matthew", ScreenTip:="", TextToDisplay:="Matt."
Loop
End With

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
>I am advanced in Word, but new to using VBA, having watched Steph Krieger's
> Webcast and read a few of your MVP articles on editing macros in VBA. I
[quoted text clipped - 37 lines]
> SubAddress:="Matthew", ScreenTip:="", TextToDisplay:="Matt."
> End Sub