How to create a form dropdown/combobox that contains all of the active styles in a word document?

I need to create a combobox dropdown that contains all of the active styles in a word document. Would this be done by creating an array and then passing the array values to the combobox? what would the code for that look like?
Joshua MartinezAsked:
Who is Participating?
 
GrahamSkanRetiredCommented:
You can add items directly to a combobox on a UserForm with code like this
Private Sub cmdListStyles_Click()
    Dim sty As Style
    For Each sty In ActiveDocument.Styles
        If sty.InUse Then
            ComboBox1.AddItem sty.NameLocal
        End If
    Next sty
End Sub

Open in new window

0
 
Joshua MartinezAuthor Commented:
The above doesn't seem to be returning any styles to the box. Perhaps I am missing something.
0
 
GrahamSkanRetiredCommented:
Can you post a sample document, please?
0
 
Joshua MartinezAuthor Commented:
I figured it out. All it needed was to be put in a different module named as such:
Private Sub UserForm_Initialize()
     Dim sty As Style
     For Each sty In ActiveDocument.Styles
         If sty.InUse Then
              ComboBox1.AddItem sty.NameLocal
         End If
     Next sty
End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.