replace fillin with ask fields & add references
Hello Everyone,
I am trying to write a procedure in Word 2000 to replace FILLIN fields with ASK fields.
My idea is to find each instance of of a FILLIN field, and replace the text, "FILLIN" with "ASK b1". The next text "FILLIN" I want to replace with "ASK b2", etc.
The code I wrote is replacing the text on every other instance. Does anyone know why this is?
Public Sub instance()
Public Sub tryit()
Dim rngOriginalSelection As Word.Range
Dim colFoundItems As New Collection
Dim rngCurrent As Word.Range
Dim strSearchFor As String
Dim intFindCounter As Integer
Set rngOriginalSelection = Selection.Range
strSearchFor = "FILLIN"
With Selection.Find
.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Text = strSearchFor
.Execute
Do While .Found = True
intFindCounter = intFindCounter + 1
colFoundItems.Add Selection.Range, CStr(intFindCounter)
.Execute
Loop
End With
rngOriginalSelection.Select
If MsgBox("There are " & intFindCounter & " instances of '" _
& rngOriginalSelection & "' in this document." & vbCrLf & vbCrLf _
& "Would you like to loop through and display all instances?", _
vbYesNo) = vbYes Then
intFindCounter = 0
For Each rngCurrent In colFoundItems
With Selection.Find
intFindCounter = intFindCounter + 1
.Replacement.Text = "ASK b " & intFindCounter + 1
rngCurrent.Select
MsgBox "This is instance #" & intFindCounter
' intFindCounter = intFindCounter + 1
End With
Selection.Find.Execute Replace:=wdReplaceOne
Next
End If
rngOriginalSelection.Select
End Sub
|