Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Word Automation - Menu Separators

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HaySeed - 05 Feb 2008 09:20 GMT
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.)
Shauna Kelly - 06 Feb 2008 06:11 GMT
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

> I'm using C# to automate a Word session.  At the start of the session
> I build
[quoted text clipped - 7 lines]
>  (When I try wordApp.CommandBars.Add() - I create an undocked Tool bar
> instead of adding a menu item.)
HaySeed - 06 Feb 2008 18:25 GMT
Thanks Shauna

That was a valuable and unusually complete response.  I appreciate the extra
effort.

> Hi
>
[quoted text clipped - 56 lines]
> >  (When I try wordApp.CommandBars.Add() - I create an undocked Tool bar
> > instead of adding a menu item.)
Curt - 14 May 2008 06:52 GMT
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

> Hi
>
[quoted text clipped - 56 lines]
> >  (When I try wordApp.CommandBars.Add() - I create an undocked Tool bar
> > instead of adding a menu item.)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.