R
Ray C
I need to extract telephone numbers from a Word document and insert them in
Excel. So I decided to search for the area code (450). However my loop that
executes the Find method doesn't stop, so I'm stuck in a loop.
Can anyone tell me what I'm doing wrong?
For Each rng In objDocument.StoryRanges
With rng.Find
.ClearFormatting
.Text = "450"
.Wrap = wdFindStop
.Forward = True
End With
Do Until rng.Find.Execute = False
rng.Expand Unit:=wdSentence
myArray = Split(rng.Text, " ", -1, vbTextCompare)
For i = 0 To UBound(myArray)
If InStr(1, myArray(i), "450", vbTextCompare) <> 0 Then
'Insert into excel cell
End If
Next i
Loop
Next rng
Excel. So I decided to search for the area code (450). However my loop that
executes the Find method doesn't stop, so I'm stuck in a loop.
Can anyone tell me what I'm doing wrong?
For Each rng In objDocument.StoryRanges
With rng.Find
.ClearFormatting
.Text = "450"
.Wrap = wdFindStop
.Forward = True
End With
Do Until rng.Find.Execute = False
rng.Expand Unit:=wdSentence
myArray = Split(rng.Text, " ", -1, vbTextCompare)
For i = 0 To UBound(myArray)
If InStr(1, myArray(i), "450", vbTextCompare) <> 0 Then
'Insert into excel cell
End If
Next i
Loop
Next rng