R
Raul
I need to find numbers in the first few characters of a paragraph and then
insert some text before the number. I have modified some code that someone
from this newsgroup was kind enough to create in response to an earlier post.
The code listed below will find the numbers and insert the text, but it
will insert the text before any numbers in the paragraphs. I need to to limit
the search to a specifed number of characters in each paragraph and ignore
any numbers that are outside that range.
Thanks in advance,
Raul
Sub FindNumberAndInsertText()
Dim i As Long
Dim rngSource As Range
Dim txt2insert As String
Dim docSource As Document
Set docSource = ActiveDocument
txt2insert = "Question "
i = 0
Do
Set rngSource = docSource.Range
i = i + 1
With rngSource.Find
.Text = CStr(i) & "."
If .Execute Then
With rngSource
.MoveStart Unit:=wdParagraph, Count:=0
.InsertBefore txt2insert
End With
Else
Exit Do
End If
End With
Loop
Set docSource = Nothing
End Sub
insert some text before the number. I have modified some code that someone
from this newsgroup was kind enough to create in response to an earlier post.
The code listed below will find the numbers and insert the text, but it
will insert the text before any numbers in the paragraphs. I need to to limit
the search to a specifed number of characters in each paragraph and ignore
any numbers that are outside that range.
Thanks in advance,
Raul
Sub FindNumberAndInsertText()
Dim i As Long
Dim rngSource As Range
Dim txt2insert As String
Dim docSource As Document
Set docSource = ActiveDocument
txt2insert = "Question "
i = 0
Do
Set rngSource = docSource.Range
i = i + 1
With rngSource.Find
.Text = CStr(i) & "."
If .Execute Then
With rngSource
.MoveStart Unit:=wdParagraph, Count:=0
.InsertBefore txt2insert
End With
Else
Exit Do
End If
End With
Loop
Set docSource = Nothing
End Sub