Call macro from userdefined Ribbon

S

Steffen Grellmann

Hi Newsgroup,

I'm able to add user-defined groups and buttons to the Ribbon using
VSTO SE. Just a beginners question: What would be the best practice to
call a Outlook-Macro if a userdefined button in the ribbon is clicked?
Do I have to use "OnAction" in the xml file or do I have do use the
callback in my Ribbon.vb file? A code snipped would be very welcome.

Your time and help is highly appreciated.

Kind regards,

Steffen
 
P

Patrick Schmid [MVP]

You have to specift the onAction attribute in the RibbonX and implement
the appropriate callback in your VB file. You should consult
http://msdn2.microsoft.com/en-us/library/aa722523.aspx for the correct
VB syntax of the callback.
Basically you'd have something like this in your RibbonX:
<button id="MyButton" onAction="myCallback" />

And in VB:
Sub myCallback(control as IRibbonControl)

End Sub

Keep in mind that if you are targeting more than one inspector in
Outlook, you'll have to evaluate the context attribute of the
IRibbonControl to figure out which Inspector triggered the callback.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed
 
S

Steffen Grellmann

Hi Patrick,

thank you very much for replying!

This is working for me so far. I can show a MsgBox from Sub
myCallback. But how can I call an Outlook-macro from there or open a
form which is part of my VbaProject.OTM file (VBA)? I assume it would
be a better strategy to migrate them to an Add-In (especially for use
with Office 2007!) but I'm afraid I have to write all the code and
forms new and I'm not very experienced with VS 2005 so far.

If you could tell me how the macro could be called from the callback
Sub I would appreciated that very much.

Kind regards,

Steffen Grellmann

You have to specift the onAction attribute in the RibbonX and implement
the appropriate callback in your VB file. You should consult
http://msdn2.microsoft.com/en-us/library/aa722523.aspx for the correct
VB syntax of the callback.
Basically you'd have something like this in your RibbonX:
<button id="MyButton" onAction="myCallback" />

And in VB:
Sub myCallback(control as IRibbonControl)

End Sub

Keep in mind that if you are targeting more than one inspector in
Outlook, you'll have to evaluate the context attribute of the
IRibbonControl to figure out which Inspector triggered the callback.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


Hi Newsgroup,

I'm able to add user-defined groups and buttons to the Ribbon using
VSTO SE. Just a beginners question: What would be the best practice to
call a Outlook-Macro if a userdefined button in the ribbon is clicked?
Do I have to use "OnAction" in the xml file or do I have do use the
callback in my Ribbon.vb file? A code snipped would be very welcome.

Your time and help is highly appreciated.

Kind regards,

Steffen
 
P

Patrick Schmid [MVP]

Hi Steffen,

I think the Outlook inspector or application class has a command to
execute a VBA macro. Are you using VSTO or not?
Quite frankly though, I'd look into migrating your add-in...

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed

Hi Patrick,

thank you very much for replying!

This is working for me so far. I can show a MsgBox from Sub
myCallback. But how can I call an Outlook-macro from there or open a
form which is part of my VbaProject.OTM file (VBA)? I assume it would
be a better strategy to migrate them to an Add-In (especially for use
with Office 2007!) but I'm afraid I have to write all the code and
forms new and I'm not very experienced with VS 2005 so far.

If you could tell me how the macro could be called from the callback
Sub I would appreciated that very much.

Kind regards,

Steffen Grellmann

You have to specift the onAction attribute in the RibbonX and implement
the appropriate callback in your VB file. You should consult
http://msdn2.microsoft.com/en-us/library/aa722523.aspx for the correct
VB syntax of the callback.
Basically you'd have something like this in your RibbonX:
<button id="MyButton" onAction="myCallback" />

And in VB:
Sub myCallback(control as IRibbonControl)

End Sub

Keep in mind that if you are targeting more than one inspector in
Outlook, you'll have to evaluate the context attribute of the
IRibbonControl to figure out which Inspector triggered the callback.

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://pschmid.net/office2007/ribboncustomizer
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed


Hi Newsgroup,

I'm able to add user-defined groups and buttons to the Ribbon using
VSTO SE. Just a beginners question: What would be the best practice to
call a Outlook-Macro if a userdefined button in the ribbon is clicked?
Do I have to use "OnAction" in the xml file or do I have do use the
callback in my Ribbon.vb file? A code snipped would be very welcome.

Your time and help is highly appreciated.

Kind regards,

Steffen
 
S

Steffen Grellmann

Hi Patrick,

thank you very much for your assistance.

I think the Outlook inspector or application class has a command to
execute a VBA macro.

I'm going to search for a solution on the internet for this matter. If
I've figured it out, I'm going to post it here.
Are you using VSTO or not?

Yes, I'm using VSTO 2005 SE.
Quite frankly though, I'd look into migrating your add-in...

I guess also this would be the best way.

Kind regards,

Steffen
 
K

Ken Slovak - [MVP - Outlook]

You can call a macro or open a VBA UserForm from your addin but that's
definitely not a best practice. It works but it's not supported, and even if
you use it and it works it might not work in the future.

To call a macro from outside you must create it in ThisOutlookSession, as a
public Sub with no input arguments. To open a UserForm you must have a
public macro that calls to open the form, it's not accessible any other way.

If the macro is in ThisOutlookSession and has the name "Foobar" you would
call it as Application.Foobar. Application in this case is
Outlook.Application, so if you have the addin store the Application object
as _outlook then the call would be to _outlook.Foobar().
 

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