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
--
Thanks, Danke sehr, Merci!
Alice

Re: VBA - Help defining for a "For Each....Next" command by Doug

Doug
Sat Jul 30 13:44:53 CDT 2005

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


--
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
"Alice" <aa.mccoy@deletefakeComcast.net> wrote in message
news:4C2C59E5-B426-4C6E-AA3D-C07FAF2DF872@microsoft.com...
>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
> --
> Thanks, Danke sehr, Merci!
> Alice