Onaction not working in Project 2007

T

thoff

I got a book on VBA programming in Project("VBA Programming for Microsoft
Office Project") but the custom menu examples don't work in Project 2007.
Doing some research, microsoft doesn't support the old way of doing custom
menus any more. Can someone point me to where the new procedure for doing
custom pull down menus is described? Here is what the book has that doesn't
work. Thanks in advance.

Sub AddMenu()
Dim MyMenu As CommandBarControl
Dim MyButton As CommandBarButton
On Error Resume Next
Set MyMenu = CommandBars("Menu Bar") _
.Controls("My Menu")
If MyMenu Is Nothing Then
Set MyMenu = CommandBars("Menu Bar") _
.Controls.Add(Type:=msoControlPopup, _
ID:=1, Before:=9, Temporary:=True)
MyMenu.Caption = "My Menu"
MyMenu.Enabled = True
Set MyButton = MyMenu.Controls.Add( _
Type:=msoControlButton, ID:=1, Before:=1)
With MyButton
.OnAction = "AddToolbar"
.Enabled = True
.Style = msoButtonCaption
.Caption = "Add Toolbar"
End With
Set MyButton = MyMenu.Controls.Add( _
Type:=msoControlButton, ID:=1, Before:=2)
With MyButton
.OnAction = "DeleteBar"
.Style = msoButtonCaption
.Caption = "Delete Toolbar"
End With
Set MyButton = MyMenu.Controls.Add( _
Type:=msoControlButton, ID:=1, Before:=3)
With MyButton
.OnAction = "DeleteMenu"
.Style = msoButtonCaption
.Caption = "Delete Menu"
End With
End If
End Sub
 
R

Rod Gill

Hi,

That's my bad. I wrote that code before Project 2007 was released and I
didn't test it on 2007 ;-(

Unfortunately Project 2007 does not support programmatic setting of the
onaction property for security reasons =!@##$$%@#$!

You either have to set the actions manually or create a Project Add-in.

Hope the rest of the book works for you!

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
T

thoff

Rod,

I do like the rest of the book and think it will help with what I'm doing.
Can you point me in the right direction when you say set the actions
manually? I found some code that used an addhandler call to do that but it
looks like it is for visual studio because my VB editor didn't understand
that command. Thanks.
 
R

Rod Gill

Right-mouse-click any toolbar and select customize.
Click on the toolbar button to edit
Click Modify Selection in the Customize dialog and update the settings.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top