I'm using C# to automate a Word session. At the start of the session I build a custom set of menu items under the "Tools" CommandBar. 2 Questions: 1) How do I add a menu Separator into my custom menus 2) How do I add a new Item to the top menu Command Bar. (When I try wordApp.CommandBars.Add() - I create an undocked Tool bar instead of adding a menu item.)
Hi 1. The CommandBarControl object and the CommandBarButton object both have a .BeginGroup parameter. Set it to True to get Word to insert the horizontal or vertical line before this item on a command bar or menu. 2. The top menu is just a command bar (named "Menu Bar"). So: Sub xxx() Dim barMenuBar As CommandBar Dim oButton As CommandBarButton Dim oMenu As CommandBarPopup Dim oMenuButton As CommandBarButton Application.CustomizationContext = ActiveDocument Set barMenuBar = CommandBars("Menu Bar") Set oButton = barMenuBar.Controls.Add(Type:=msoControlButton) With oButton .BeginGroup = True .Caption = "Test button" .Style = msoButtonCaption End With Set oMenu = barMenuBar.Controls.Add(Type:=msoControlPopup) With oMenu .BeginGroup = True .Caption = "Test menu" End With Set oMenuButton = oMenu.Controls.Add(Type:=msoControlButton) With oMenuButton .Caption = "My button on a menu" .Style = msoButtonCaption End With End Sub 3. Make sure you set the CustomizationContext before you begin. It's not polite to change a user's Normal.dot. And, it's not good practice to set the CustomizationContext to your addin or to a template and allow the user to get a "do you want to save" message; so set the .Saved property of the relevant template to True when you're finished. Hope this helps. Shauna Kelly. Microsoft MVP. http://www.shaunakelly.com/word "HaySeed" wrote in message news:FFA81598-DEA5-4305-AEC0-9A6A4EC45771@microsoft.com... > I'm using C# to automate a Word session. At the start of the session > I build > a custom set of menu items under the "Tools" CommandBar. > > 2 Questions: > > 1) How do I add a menu Separator into my custom menus > > 2) How do I add a new Item to the top menu Command Bar. > (When I try wordApp.CommandBars.Add() - I create an undocked Tool bar > instead of adding a menu item.)
Thanks Shauna That was a valuable and unusually complete response. I appreciate the extra effort. "Shauna Kelly" wrote: > Hi > > 1. The CommandBarControl object and the CommandBarButton object both > have a .BeginGroup parameter. Set it to True to get Word to insert the > horizontal or vertical line before this item on a command bar or menu. > > 2. The top menu is just a command bar (named "Menu Bar"). So: > > Sub xxx() > > Dim barMenuBar As CommandBar > Dim oButton As CommandBarButton > Dim oMenu As CommandBarPopup > Dim oMenuButton As CommandBarButton > > Application.CustomizationContext = ActiveDocument > > Set barMenuBar = CommandBars("Menu Bar") > Set oButton = barMenuBar.Controls.Add(Type:=msoControlButton) > With oButton > .BeginGroup = True > .Caption = "Test button" > .Style = msoButtonCaption > End With > > Set oMenu = barMenuBar.Controls.Add(Type:=msoControlPopup) > With oMenu > .BeginGroup = True > .Caption = "Test menu" > End With > Set oMenuButton = oMenu.Controls.Add(Type:=msoControlButton) > With oMenuButton > .Caption = "My button on a menu" > .Style = msoButtonCaption > End With > > End Sub > > > 3. Make sure you set the CustomizationContext before you begin. It's not > polite to change a user's Normal.dot. And, it's not good practice to set > the CustomizationContext to your addin or to a template and allow the > user to get a "do you want to save" message; so set the .Saved property > of the relevant template to True when you're finished. > > Hope this helps. > > Shauna Kelly. Microsoft MVP. > http://www.shaunakelly.com/word > > > > > > "HaySeed" wrote in message > news:FFA81598-DEA5-4305-AEC0-9A6A4EC45771@microsoft.com... > > I'm using C# to automate a Word session. At the start of the session > > I build > > a custom set of menu items under the "Tools" CommandBar. > > > > 2 Questions: > > > > 1) How do I add a menu Separator into my custom menus > > > > 2) How do I add a new Item to the top menu Command Bar. > > (When I try wordApp.CommandBars.Add() - I create an undocked Tool bar > > instead of adding a menu item.) > > >
Read your responce to another. Good reply. My question is it possible to have msword 2000 macro reconize 1 comma as a seperator. When I record it shows Separator:=wdSeparateByCommas, In debug Commas=2 comma=0comma=1 not accepted. The text file I create in excel has 1 comma between fields. The macro in word will not go past the set delimiter screen no matter how I try to set it. Have been all over net with no avail. Appreciate any help Greatly "Shauna Kelly" wrote: > Hi > > 1. The CommandBarControl object and the CommandBarButton object both > have a .BeginGroup parameter. Set it to True to get Word to insert the > horizontal or vertical line before this item on a command bar or menu. > > 2. The top menu is just a command bar (named "Menu Bar"). So: > > Sub xxx() > > Dim barMenuBar As CommandBar > Dim oButton As CommandBarButton > Dim oMenu As CommandBarPopup > Dim oMenuButton As CommandBarButton > > Application.CustomizationContext = ActiveDocument > > Set barMenuBar = CommandBars("Menu Bar") > Set oButton = barMenuBar.Controls.Add(Type:=msoControlButton) > With oButton > .BeginGroup = True > .Caption = "Test button" > .Style = msoButtonCaption > End With > > Set oMenu = barMenuBar.Controls.Add(Type:=msoControlPopup) > With oMenu > .BeginGroup = True > .Caption = "Test menu" > End With > Set oMenuButton = oMenu.Controls.Add(Type:=msoControlButton) > With oMenuButton > .Caption = "My button on a menu" > .Style = msoButtonCaption > End With > > End Sub > > > 3. Make sure you set the CustomizationContext before you begin. It's not > polite to change a user's Normal.dot. And, it's not good practice to set > the CustomizationContext to your addin or to a template and allow the > user to get a "do you want to save" message; so set the .Saved property > of the relevant template to True when you're finished. > > Hope this helps. > > Shauna Kelly. Microsoft MVP. > http://www.shaunakelly.com/word > > > > > > "HaySeed" wrote in message > news:FFA81598-DEA5-4305-AEC0-9A6A4EC45771@microsoft.com... > > I'm using C# to automate a Word session. At the start of the session > > I build > > a custom set of menu items under the "Tools" CommandBar. > > > > 2 Questions: > > > > 1) How do I add a menu Separator into my custom menus > > > > 2) How do I add a new Item to the top menu Command Bar. > > (When I try wordApp.CommandBars.Add() - I create an undocked Tool bar > > instead of adding a menu item.) > > >