0
votes

I have lot of documents with list number typed manually, so my intent is to remove those manual list number and the tab or space following it. e.g
1. Text 1
1.1 Text 2
1.1.1 Text 3
1.1.1.1 Text 4

become
Text 1
Text 2
Text 3
Text 4

I'm not sure how to do this with vba and I'd really appreciate your help.

1

1 Answers

0
votes

I have figured it out by using below code:

Sub RemoveManualListNumber()
  Dim strInitialPar As String
  Dim intSpace As Integer, intTab As Integer
  Dim strFinalPar As String
  Dim iPar

    For iPar = 1 To ActiveDocument.Paragraphs.Count
    strInitialPar = ActiveDocument.Paragraphs(iPar).Range.Text
    intSpace = InStr(1, strInitialPar, " ")
    intTab = InStr(1, strInitialPar, Chr(9))

        Debug.Print "Paragraph " & iPar & ": " & "Index space = " & intSpace & ", Index tab = " & intTab

        If intTab > 0 And intTab < intSpace Then
              strFinalPar = Right(strInitialPar, Len(strInitialPar) - intTab)
              Else
              strFinalPar = Right(strInitialPar, Len(strInitialPar) - intSpace)
          End If

          ActiveDocument.Paragraphs(iPar).Range.Text = strFinalPar
    Next iPar
End sub