View Single Post
 
Old 08-03-2021, 01:05 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,142
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 ofgmayor has much to be proud of
Default

You can include any style parameters e.g. as follows

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
            Set MyStyle = Application.ActiveDocument.Styles.Add(CStr(vStyle(i)), wdStyleTypeParagraph)
            With MyStyle
                Select Case i
                    Case 0
                        .Font.Name = "Calibri"
                        .Font.Size = 12
                    Case 1
                        .Font.Name = "Times New Roman"
                        .Font.Bold = True
                        .Font.Size = 16
                    Case 2
                        .Font.Name = "Times New Roman"
                        .Font.Italic = True
                        .Font.Size = 14
                    Case 3
                        .Font.Name = "Times New Roman"
                        .Font.Superscript = True
                        .Font.Size = 12
                        'etc
                End Select
            End With
        End If
        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