Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Menu of Commands in Project

Status
Not open for further replies.

gregsedwards

Instructor
Jan 10, 2002
11
US
Hi all,

I am trying to add a custom menu with commands that run various macros I've written into the project file. I could create the toolbars manually, but I want them tied to the MPP file, not my installation of Project. So I'm trying to create the menu and commands programmatically.

I know this a pretty common thing in Office apps. You typically tie the code that builds your toolbars to an file-level event handler, such as Project_Open(), and you destroy the custom tools in conjunction with another event handler, like Project_BeforeClose(). It's the in-between coding that baffles me.

Could anyone explain how you append a new menu to the end of the main menu bar, load it up with a few menu commands, and tie those menu commands to macros? If you're feeling generous, a few code snippets would really be helpful. Thanks in advance!

- Greg
 
Hi Greg,

This is some basic code to get you going. You will need to put your own names (see italicised text in code below) in it, and the OnAction routines must exist before you attach them.

Code:
[blue]Private Sub Project_Open(ByVal pj As Project)

Dim cbc As CommandBarControl
Dim cbc2 As CommandBarControl

Set cbc = Application.CommandBars("Menu Bar").Controls.Add(msoControlPopup, Temporary:=True)
cbc.Caption = "[i]Ton&y[/i]"

Set cbc2 = cbc.Controls.Add(msoControlButton, Temporary:=True)
cbc2.Caption = "[i]First Thing[/i]"
cbc2.OnAction = "[i]Thing1[/i]"

Set cbc2 = cbc.Controls.Add(msoControlButton, Temporary:=True)
cbc2.Caption = "[i]Second Thing[/i]"
cbc2.OnAction = "[i]Thing2[/i]"

Set cbc2 = cbc.Controls.Add(msoControlButton, Temporary:=True)
cbc2.Caption = "[i]Third Thing[/i]"
cbc2.OnAction = "[i]Thing3[/i]"

Set cbc2 = Nothing
Set cbc = Nothing

End Sub



Private Sub Project_BeforeClose(ByVal pj As Project)

Application.CommandBars("Menu Bar").Controls("[i]Tony[/i]").Delete

End Sub[/blue]

Do come back if you need any further help with any of it.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top