C
Casey Mac
Greetings.
I would like for a user to input a word into a form and then a second form
appears that asks what to link to. I have (i think) the code so that if a
word in this case "ability" is found it will replace all occurances of
"ablity" with a hyperlink (c:\test.txt). What i need is to populate those
variables with what a user inputs.
Please help
Thanks in advance.
Sub FindAndReplaceWithHypertext()
Dim rngReplace As Word.Range
Dim rngFound As Word.Range
Dim szFindTerm As String
szFindTerm = InputBox("Enter the word you wish to replace with a
hyperlink:")
Set rngReplace = ActiveDocument.Content
With rngReplace.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "ability"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
' Find all occurrences in the document
Do While .Execute
' Create and use a totally independent range object
Set rngFound = rngReplace.Duplicate
' Replace sought text with hyperlink
rngFound.Text = vbNullString
ActiveDocument.Hyperlinks.Add rngFound, "c:\test.txt", _
TextToDisplay:="test"
' Resume the search after the text that we just found
rngReplace.Collapse wdCollapseEnd
Loop
End With
End Sub
I would like for a user to input a word into a form and then a second form
appears that asks what to link to. I have (i think) the code so that if a
word in this case "ability" is found it will replace all occurances of
"ablity" with a hyperlink (c:\test.txt). What i need is to populate those
variables with what a user inputs.
Please help
Thanks in advance.
Sub FindAndReplaceWithHypertext()
Dim rngReplace As Word.Range
Dim rngFound As Word.Range
Dim szFindTerm As String
szFindTerm = InputBox("Enter the word you wish to replace with a
hyperlink:")
Set rngReplace = ActiveDocument.Content
With rngReplace.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "ability"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
' Find all occurrences in the document
Do While .Execute
' Create and use a totally independent range object
Set rngFound = rngReplace.Duplicate
' Replace sought text with hyperlink
rngFound.Text = vbNullString
ActiveDocument.Hyperlinks.Add rngFound, "c:\test.txt", _
TextToDisplay:="test"
' Resume the search after the text that we just found
rngReplace.Collapse wdCollapseEnd
Loop
End With
End Sub