Helmi
asked on
WORD-VBA, exchange Stylenames
How does word create the pull down menu with sytlenames of the active document?
I want to create two pull down menus, one should show the stylnames of the active document, the other the stylenames of the attached template.
I want to create two pull down menus, one should show the stylnames of the active document, the other the stylenames of the attached template.
Helmi -- this isn't an answer, but if you want to see all of the styles attached to a particular template from the existing drop down menu, you can hold your shift key down as you activate the menu; that will show all styles instead of those currently in use. Then you can use the same menu for both situations.
I also can give you only a partial answer for now. You can create/customize a toolbar this way:
a) View|Toolbars|Customize|Ne w
b) Choose a new name, say 'Helmi', will create a new floating bar, better than to alter the existing ones.
c) In the customize dialog change to the Command tab, there select the Format category. Drag the Style icon to the your new toolbar
d) Close the dialog
e) Place your toolbar where you want it
Will see what I can look something up in the MSKB. If you want to try it too: For persons using the english version bookmark this URL:
http://search.microsoft.com/us/SearchMS.asp
For other languages, access the a.m. URL then switch to the appropriate country using the listbox in the upper left corner before bookmarking.
a) View|Toolbars|Customize|Ne
b) Choose a new name, say 'Helmi', will create a new floating bar, better than to alter the existing ones.
c) In the customize dialog change to the Command tab, there select the Format category. Drag the Style icon to the your new toolbar
d) Close the dialog
e) Place your toolbar where you want it
Will see what I can look something up in the MSKB. If you want to try it too: For persons using the english version bookmark this URL:
http://search.microsoft.com/us/SearchMS.asp
For other languages, access the a.m. URL then switch to the appropriate country using the listbox in the upper left corner before bookmarking.
Did not find a way yet, probably some VBA must be done. Wait for the VBA addicts.
In the meanwhile, bookmark this one, is handy:
http://www.microsoft.com/officedev/articles/Opg/toc/PGTOC.htm
Might help:
Chapter 7 of a.m. guide (use find 'styles')
http://msdn.microsoft.com/library/officedev/office97/web/007.htm
Chapter 8
http://www.microsoft.com/OfficeDev/Articles/OPG/008/008.HTM
In the meanwhile, bookmark this one, is handy:
http://www.microsoft.com/officedev/articles/Opg/toc/PGTOC.htm
Might help:
Chapter 7 of a.m. guide (use find 'styles')
http://msdn.microsoft.com/library/officedev/office97/web/007.htm
Chapter 8
http://www.microsoft.com/OfficeDev/Articles/OPG/008/008.HTM
ASKER
I am looking for a proper VBA command. I created a macro where you can change stylenames , for example change all Heading 5 to Heading 3. Instead of typing the stylename, I want to put them into a pull down menu. One should show all stylnames in use of the active document, the other all stylenames off the current template.
ASKER
Adjusted points to 150
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Helmi,
Here is a procedure that creates a toolbar with two dropdowns, showing used and unused styles.
Sub CreateStyleDropDowns()
Dim cbar As CommandBar
Dim drop1 As CommandBarControl
Dim drop2 As CommandBarControl
Dim st As Style
'Delete commandbar if it exists
On Error Resume Next
CommandBars("Ture").Delete
On Error GoTo 0
'Create new commandbar
Set cbar = CommandBars.Add(Name:="Tur e", Position:=msoBarFloating, Temporary:=True)
'Create two dropdowns to the new commandbar
Set drop1 = cbar.Controls.Add(Type:=ms oControlDr opdown, Temporary:=True)
Set drop2 = cbar.Controls.Add(Type:=ms oControlDr opdown, Temporary:=True)
'Set the procedure to be started when clicking the dropdowns
drop1.OnAction = "drop1_change"
drop1.TooltipText = "Styles used in this document"
drop2.OnAction = "drop2_change"
drop2.TooltipText = "Unused styles in the template"
'Add style names to the dropdowns
For Each st In ActiveDocument.Styles
If st.InUse Then
drop1.AddItem st.NameLocal
Else
drop2.AddItem st.NameLocal
End If
Next st
'Show the commandbar
cbar.Visible = True
End Sub
Sub drop1_change()
'Show the text of the first dropdown
MsgBox CommandBars("Ture").Contro ls(1).Text
End Sub
Sub drop2_change()
'Show the text of the second dropdown
MsgBox CommandBars("Ture").Contro ls(2).Text
End Sub
/Ture
Here is a procedure that creates a toolbar with two dropdowns, showing used and unused styles.
Sub CreateStyleDropDowns()
Dim cbar As CommandBar
Dim drop1 As CommandBarControl
Dim drop2 As CommandBarControl
Dim st As Style
'Delete commandbar if it exists
On Error Resume Next
CommandBars("Ture").Delete
On Error GoTo 0
'Create new commandbar
Set cbar = CommandBars.Add(Name:="Tur
'Create two dropdowns to the new commandbar
Set drop1 = cbar.Controls.Add(Type:=ms
Set drop2 = cbar.Controls.Add(Type:=ms
'Set the procedure to be started when clicking the dropdowns
drop1.OnAction = "drop1_change"
drop1.TooltipText = "Styles used in this document"
drop2.OnAction = "drop2_change"
drop2.TooltipText = "Unused styles in the template"
'Add style names to the dropdowns
For Each st In ActiveDocument.Styles
If st.InUse Then
drop1.AddItem st.NameLocal
Else
drop2.AddItem st.NameLocal
End If
Next st
'Show the commandbar
cbar.Visible = True
End Sub
Sub drop1_change()
'Show the text of the first dropdown
MsgBox CommandBars("Ture").Contro
End Sub
Sub drop2_change()
'Show the text of the second dropdown
MsgBox CommandBars("Ture").Contro
End Sub
/Ture