for each oPara in Paragraphs touches each paragraph twice

A

alevansal

I've written a procedure that removes any numbering from the beginning of
each paragraph that seems to work. However, the For Each loop touches each
paragraph twice: once to edit it and once after it's edited. What do I need
to do to prevent the procedure from revisiting an edited paragraph?

Sub FixNumbering(destdoc)
Dim oPara As Paragraph
Dim myString As String
Dim code As Integer
Dim position1 As Long
Dim position2 As Long

Documents(destdoc).Activate

For Each oPara In ActiveDocument.Paragraphs
If oPara.Style = "NumLev1" Or oPara.Style = "NumLev2" Or oPara.Style =
"NumLev3" Or _
oPara.Style = "NumLev4" Or oPara.Style = "NumLev5" Or oPara.Style =
"NumLev6" Then
myString = oPara.Range.Text
position1 = InStr(myString, ".")
position2 = InStr(myString, ")")
If position1 > 0 And position1 < 5 Then
Debug.Print "Before: " + oPara.Range.Text
oPara.Range.Text = RemovedNumbering(myString, position1)
ElseIf position2 > 0 And position2 < 5 Then
Debug.Print "Before: " + oPara.Range.Text
oPara.Range.Text = RemovedNumbering(myString, position2)
End If
oPara.ID
End If
Next oPara
Documents(destdoc).Save
End Sub

-----------------------------------------------------------------------

Function RemovedNumbering(theString, pos) As String
Dim code As Integer

RemovedNumbering = Mid(theString, pos + 1)
code = Asc(RemovedNumbering)

Do While code = 32 Or code = 160
RemovedNumbering = Mid(RemovedNumbering, 2)
code = Asc(RemovedNumbering)
Loop

Debug.Print "After: " + RemovedNumbering

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top