PDA

View Full Version : Capture styles from template



Rathish
07-26-2013, 03:34 AM
Hi,
Is there any way to capture all the styles of selected word template in a dropdown box of a userform.
So if i want to apply a style to a document i select the template>> in a userform's dropdown box all styles get loaded. Looking to do through VBA...But don't know how to cature styles of the selected template in drop down box.
Please help

Thanks
Radhish

Rathish
07-26-2013, 11:19 PM
Hi,
Is there any way to capture all the styles of selected word template in a dropdown box of a userform.
So if i want to apply a style to a document i select the template>> in a userform's dropdown box all styles get loaded. Looking to do through VBA...But don't know how to cature styles of the selected template in drop down box.
Please help

Thanks
Radhish


I tried below to get the below code. but the the value is not appearing in the drop down list. Please help me.

Global new_text As String
Sub Apply_style()
Dim i As Integer
Dim MyArray()
Dim k As Integer
Dim old_txt As String
k = 0
ActiveDocument.CopyStylesFromTemplate ("D:\Users\ABC\Desktop\Word template\Word Template_2013.dotx")
For j = 1 To ActiveDocument.Styles.Count
ReDim Preserve MyArray(0 To ActiveDocument.Styles.Count)
MyArray(k) = ActiveDocument.Styles(j)
j = j + 1
k = k + 1
Next
For M = 1 To ActiveDocument.Styles.Count
old_txt = MyArray(M)
new_text = new_text & vbCrLf & ", " & old_txt
Next
UserForm1.ComboBox1.Value = new_text
UserForm1.Show

end sub