C
Casey Mac
hello,
What im wanting to try is for this code to cycle through the document and
once you have imputted your criteria:
sFnd = Enter the word you wish to replace with a hyperlink
sHpl = Enter File Name
sDsp = Enter the HyperLink display name
it will prompt you once it finds the word you wish to replace. At that
point you can choose either yes (to replace it) or no to ignore it.
Im thinking this must be a simple if statement but for the life of me i cant
find where it should go. I have a partial piece "MsgBox "Replace selection",
vbYesNo, "Testing" but cant figure out the rest.
Please help. i would like to try and sleep tonight.
Thanks
cm
Sub FindAndReplaceWithHypertext()
Dim rDoc As Range ' range replace
Dim sFnd As String ' string to be found
Dim sHpl As String ' hyperlink
Dim sDsp As String ' hyperlink display
sFnd = InputBox("Enter the word you wish to replace with a hyperlink:")
sHpl = InputBox("Enter File Name:")
sDsp = InputBox("Enter the HyperLink display name")
Set rDoc = ActiveDocument.Range
ResetSearch
With rDoc.Find
.Text = sFnd
.Wrap = wdFindStop
MsgBox "Replace selection", vbYesNo, "Testing"
Do While .Execute
ActiveDocument.Hyperlinks.Add _
rDoc, sHpl, TextToDisplay:=sDsp
rDoc.End = rDoc.End + Len(sDsp)
rDoc.Collapse wdCollapseEnd
Loop
End With
End Sub
What im wanting to try is for this code to cycle through the document and
once you have imputted your criteria:
sFnd = Enter the word you wish to replace with a hyperlink
sHpl = Enter File Name
sDsp = Enter the HyperLink display name
it will prompt you once it finds the word you wish to replace. At that
point you can choose either yes (to replace it) or no to ignore it.
Im thinking this must be a simple if statement but for the life of me i cant
find where it should go. I have a partial piece "MsgBox "Replace selection",
vbYesNo, "Testing" but cant figure out the rest.
Please help. i would like to try and sleep tonight.
Thanks
cm
Sub FindAndReplaceWithHypertext()
Dim rDoc As Range ' range replace
Dim sFnd As String ' string to be found
Dim sHpl As String ' hyperlink
Dim sDsp As String ' hyperlink display
sFnd = InputBox("Enter the word you wish to replace with a hyperlink:")
sHpl = InputBox("Enter File Name:")
sDsp = InputBox("Enter the HyperLink display name")
Set rDoc = ActiveDocument.Range
ResetSearch
With rDoc.Find
.Text = sFnd
.Wrap = wdFindStop
MsgBox "Replace selection", vbYesNo, "Testing"
Do While .Execute
ActiveDocument.Hyperlinks.Add _
rDoc, sHpl, TextToDisplay:=sDsp
rDoc.End = rDoc.End + Len(sDsp)
rDoc.Collapse wdCollapseEnd
Loop
End With
End Sub