View Single Post
 
Old 08-02-2021, 11:55 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

How about. Change the style names as required

Code:
Option Explicit

Sub AddStylesFromList()
Dim MyStyle As Style
Dim bExists As Boolean
Dim i As Integer
Dim vStyle(19) As Variant
    vStyle(0) = "Stylename1"
    vStyle(1) = "Stylename2"
    vStyle(2) = "Stylename3"
    vStyle(3) = "Stylename4"
    vStyle(4) = "Stylename5"
    vStyle(5) = "Stylename6"
    vStyle(6) = "Stylename7"
    vStyle(7) = "Stylename8"
    vStyle(8) = "Stylename9"
    vStyle(9) = "Stylename10"
    vStyle(10) = "Stylename11"
    vStyle(11) = "Stylename12"
    vStyle(12) = "Stylename13"
    vStyle(13) = "Stylename14"
    vStyle(14) = "Stylename15"
    vStyle(15) = "Stylename16"
    vStyle(16) = "Stylename17"
    vStyle(17) = "Stylename18"
    vStyle(18) = "Stylename19"
    vStyle(19) = "Stylename20"

    On Error Resume Next
    For i = 0 To 19
        bExists = style_exists(ActiveDocument, CStr(vStyle(i)))
        If bExists = False Then Application.ActiveDocument.Styles.Add CStr(vStyle(i)), wdStyleTypeParagraph
        DoEvents
    Next i
End Sub

Function style_exists(test_document As Word.Document, style_name As String) As Boolean
    style_exists = False
    On Error Resume Next
    style_exists = test_document.Styles(style_name).NameLocal = style_name
End Function
__________________
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