View Single Post
 
Old 04-30-2021, 09:23 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If the start texts are typed text and not outline numbers, the following will work
Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 01 May 2021 
Dim oPara As Word.Paragraph
Dim oRng As Range
Dim vChar1 As Variant, vChar2 As Variant, vChar3 As Variant
Dim iList As Integer

Const strList1 As String = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
Const strList2 As String = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
Const strList3 As String = "0,1,2,3,4,5,6,7,8,9"

    vChar1 = Split(strList1, ",")
    vChar2 = Split(strList2, ",")
    vChar3 = Split(strList3, ",")

    If ActiveDocument.Bookmarks.Exists("Z1") = True Then
        Set oRng = ActiveDocument.Bookmarks("Z1").Range
        For Each oPara In oRng.Paragraphs
            For iList = 0 To UBound(vChar1)
                If oPara.Range.Characters(1) = vChar1(iList) And _
                   oPara.Range.Characters(2) = Chr(46) Then
                    oPara.Style = "Heading 1"
                    GoTo Skip
                End If
            Next iList
            For iList = 0 To UBound(vChar2)
                If oPara.Range.Characters(2) = vChar2(iList) And _
                   oPara.Range.Characters(1) = Chr(40) Then
                    oPara.Style = "Heading 3"
                    GoTo Skip
                End If
            Next iList
            For iList = 0 To UBound(vChar3)
                If oPara.Range.Characters(2) = vChar3(iList) And _
                   oPara.Range.Characters(1) = Chr(40) Then
                    oPara.Style = "Heading 2"
                    GoTo Skip
                End If
            Next iList
Skip:
        Next oPara
    End If
    Set oRng = Nothing
    Set oPara = Nothing
End Sub
If they are outline numbers then associate the styles with the outline levels.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote