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
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