CommandBar and Button Actions

M

Mask

Hello Developers,

I work in Ms Project 2003 and 2007 using VB editor. I'm trying to add
a button to one bar. I created the bar and the button and they appear
when i launch project, but when i click it nothing happen.


At my Microsoft Project Object i have this code:

Private Sub Project_Open(ByVal pj As Project)
Dim myBar As CommandBar
Dim myButton As CommandBarButton

If myButton Is Nothing Then
Set myBar = CommandBars.Add(Name:="Export",
Position:=msoBarFloating, Temporary:=True)
myBar.Visible = True
Set myButton = myBar.Controls.Add(Type:=msoControlButton)
With myButton
.OnAction = "Export"
.Style = msoButtonCaption
.Caption = "Export to Excel"
End With
Else
myBar.Visible = True
End If
End Sub



And at my module:

Sub Export()
Project "Export to Excel"
End Sub

Sub Project(Action As String)
If Action = "Export to Excel" Then
< My Code >
End If
End Sub

I can't make it work. I read some things and I begin to wonder if i
need to Copy to Global Project some information. It doesn't make many
sense to me since "it's not correct" copy things to Global Project. If
I really need, how can i make it?

I will appreciate your help with this issue because my code works
without button but it is extremely important to Client having the
button for understandable reasons.


Best regards,

Mask
 
R

Rod Gill

In Project 2007 the OnAction command has been disabled for "Security"
reasons!@#$$!

You either need to copy a toolbar already setup to your Global.mpt file or
create an Add-in.

--

Rod Gill
Microsoft MVP for Project

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

Mask

Hello Rod Gill,

Once again thank you for your help. To finish this topic I would like
to know how do I copy a toolbar to my Global.mpt. I've never needed to
do that and i don't find nothing on internet.

Best regards,

Mask
 
M

Mask

Rod Gill,

I already founded the code to CopyToGlobal from your file Project
Control Center. I saw you have 1 method called CopyToGlobal that
execute what was suppose to.

When i go to Tools > Organizer > Toolbars, i can see the tab my tab
copied in Global.mpt. In MS Project 2003 it works, but in MS Project
2007 when I press myButton from my Toolbar the action isn't executed.
The toolbar appears with the button but no action is made.

I will appreciate some help because compatibility is needed to
Clients. :S

Best regards,

Mask
 
R

Rod Gill

The OnAction code works in 2003 but has been disabled by Microsoft for 2007
for security reasons. You can still copy Toolbars from one project to
another tho.

--

Rod Gill
Microsoft MVP for Project

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



Rod Gill,

I already founded the code to CopyToGlobal from your file Project
Control Center. I saw you have 1 method called CopyToGlobal that
execute what was suppose to.

When i go to Tools > Organizer > Toolbars, i can see the tab my tab
copied in Global.mpt. In MS Project 2003 it works, but in MS Project
2007 when I press myButton from my Toolbar the action isn't executed.
The toolbar appears with the button but no action is made.

I will appreciate some help because compatibility is needed to
Clients. :S

Best regards,

Mask
 
M

Mask

Rod Gill,

I'm not sure if i understood what you are trying to say.
You said "You either need to copy a toolbar already setup to your
Global.mpt file or create an Add-in". I copied the toolbar that I had
created to my Global.mpt. The toolbar appear in Ms Project 2007
global.mpt and then i copied to the my project. But if the OnAction
code doesn't work at MS Project 2007, I suppose the toolbar doesn't
work because of that. Maybe i did something wrong on copy the toolbar.

"You can still copy Toolbars from one project to another tho" - what
do you mean? I coppied the toolbar going to Tools > Organizer >
Toolbars.

Best Regards,

Mask
 
M

Mask

Hello Developers,

This solution of manual create toolbar and associate my macro isn't
very dynamic because if you decide to save the Project file with a
different name, you will have to do every thing again.

I would like to develop an add-in but can I make it in VB editor from
Ms Project?
To write an add-in do I need to use a language that supports creating
COM components?
Do i need to program My Add-in at Visual Basic 2008 or C# 2008 or the
express editions?

If you can help me figure it out how to create an Add-in and how to
integrate it with Ms Project 2007 it would be wonderfull.


Best Regards,

Mask
 

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