Making menu with macro

M

Mocha

Hello everyone,
My name is Yogi. Could anyone help me, how to create custom menu (in menu
bar) with Ms Project profesional 2007 VBA that can execute macro.
Cause i tried this, but in MenuItem.OnAction step procedure raise an error
"AutomationError Unsprcified error".
Rod Gill give me advice to create menu from View-> toolber->Customize and
record that activity but the recorded macro didn't recorded anything.
Thank you so much.

Here is my VBA Macro that raised an error:
Dim MenuObject As CommandBarPopup
Dim MenuItem As Object
Warne = "Warn"
Set MenuObject = Application.CommandBars(1). _
Controls.Add(Type:=msoControlPopup, _
Before:=11, _
Temporary:=True)
MenuObject.Caption = "&Extra Menu"

Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton, ID:=1)
MenuItem.OnAction = "macro_proecedure"
MenuItem.Caption = "Report Summary"

sub macro_procedure()
MsgBox "Helllooo"
end sub
 
R

Rod Gill

Hi,

Here is the sample code straight out of my VBA book, one of many powerful
working macros in it. Run AddMenu to create the menu and run the other
macros to add and delete toolbars and the new menu itself.

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"
Set MyButton = MyMenu.Controls.Add( _
Type:=msoControlButton, ID:=1, Before:=1)
With MyButton
.OnAction = "AddToolbar"
.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

Sub DeleteMenu()
On Error Resume Next
CommandBars("Menu Bar").Controls("My Menu").Delete
End Sub

Sub AddToolbar()
Dim MyBar As CommandBar
Dim MyButton As CommandBarButton
On Error Resume Next
Set MyBar = CommandBars("My Bar")
If MyBar Is Nothing Then
Set MyBar = CommandBars.Add(Name:="My Bar",
Position:=msoBarFloating, Temporary:=True)
MyBar.Visible = True
End If

Set MyButton = MyBar.Controls("MyButton")
If MyButton Is Nothing Then
Set MyButton = MyBar.Controls.Add(Type:=msoControlButton)
With MyButton
.Style = msoButtonCaption
.Caption = "My Macro"
.OnAction = "DeleteBar"
End With
End If
End Sub

Sub DeleteBar()
CommandBars("My Bar").Delete
End Sub

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 
S

sacgupta

The solution adds menu to Project 2007. But the support for onAction is
withdrawn in Project 2007. So how to make that work in Project 2007. Whats
the alternative we got.
 
B

bstobart

Try to use this syntax for 2007.

...OnAction = "Macro ""ShowResourceAction"""

Posted by med111 in a similar thread. [I don't know how to link between
posts.]
 
R

Rod Gill

Project 2007 has disabled the onaction method for security reasons, I think
for all Office applications!@#!@! The stated replacement is to create an
add-in which of course requires professional programmers which of course
removes the power and flexibility and productivity mere mortals like us
have.

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx


----------------------------------------------------------------------------------------------------


bstobart said:
Try to use this syntax for 2007.

..OnAction = "Macro ""ShowResourceAction"""

Posted by med111 in a similar thread. [I don't know how to link between
posts.]

Cluless Soldier said:
Rod, Did you get any response from Microsoft on this one
 
C

Chandru

Hi Rod,

Did you get any solution for this. Can you suggest any alternative
for OnAction property.

Thanks,
Chandru

Rod Gill said:
Project 2007 has disabled the onaction method for security reasons, I think
for all Office applications!@#!@! The stated replacement is to create an
add-in which of course requires professional programmers which of course
removes the power and flexibility and productivity mere mortals like us
have.

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx


----------------------------------------------------------------------------------------------------


bstobart said:
Try to use this syntax for 2007.

..OnAction = "Macro ""ShowResourceAction"""

Posted by med111 in a similar thread. [I don't know how to link between
posts.]

Cluless Soldier said:
Rod, Did you get any response from Microsoft on this one


On Aug 2, 3:35 pm, "Rod Gill" <rod AT project-systems DOT co DOT nz>
wrote:
You're right, I hadn't seen that before. The onaction compiles but
doesn't
do anything!@#! I've asked Microsoft for clarification and to see if
this is
permanent. I'll respond if I get news for you.

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx

-----------------------------------------------------------------------------------------------------





I was referring tohttp://support.microsoft.com/kb/923586

I am using somewhat similiar code but it has stopped responding.-
Hide quoted text -

- Show quoted text -
 

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