C
Casey Mac
Greetings,
Here is my code. What i would like for it to do is only work on say the
first 10 pages of a document and not go any further. I have users who will
be adding (insert - file) later on in this template and i dont want the find
replace to go and change any of the potential areas other than the first 10
pages..
Hope this makes sence. Thanks in advance
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
Do While .Execute
ActiveDocument.Hyperlinks.Add _
rDoc, sHpl, TextToDisplay:=sDsp
rDoc.End = rDoc.End + Len(sDsp)
rDoc.Collapse wdCollapseEnd
Loop
End With
End Sub
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
Here is my code. What i would like for it to do is only work on say the
first 10 pages of a document and not go any further. I have users who will
be adding (insert - file) later on in this template and i dont want the find
replace to go and change any of the potential areas other than the first 10
pages..
Hope this makes sence. Thanks in advance
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
Do While .Execute
ActiveDocument.Hyperlinks.Add _
rDoc, sHpl, TextToDisplay:=sDsp
rDoc.End = rDoc.End + Len(sDsp)
rDoc.Collapse wdCollapseEnd
Loop
End With
End Sub
Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub