Group:  Microsoft Outlook ยป microsoft.public.outlook.program_addins
Thread: Call macro from userdefined Ribbon

Geek News

Call macro from userdefined Ribbon
Steffen Grellmann <anonymous[ at ]anonym.de> 3/21/2007 10:05:22 AM
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
Re: Call macro from userdefined Ribbon
"Patrick Schmid [MVP]" <pdschmid[ at ]nospam.mvps.org> 3/21/2007 11:29:19 AM
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


"Steffen Grellmann" <anonymous[ at ]anonym.de> wrote in message
news:lk0203t7vk1je2uul0a0d5b16dqoobf6ld[ at ]4ax.com:

[Quoted Text]
> 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

Re: Call macro from userdefined Ribbon
Steffen Grellmann <anonymous[ at ]anonym.de> 3/21/2007 4:43:13 PM
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

On Wed, 21 Mar 2007 11:29:19 +0000, "Patrick Schmid [MVP]"
<pdschmid[ at ]nospam.mvps.org> wrote:

[Quoted Text]
>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
>
>
>"Steffen Grellmann" <anonymous[ at ]anonym.de> wrote in message
>news:lk0203t7vk1je2uul0a0d5b16dqoobf6ld[ at ]4ax.com:
>
>> 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

Re: Call macro from userdefined Ribbon
"Ken Slovak - [MVP - Outlook]" <kenslovak[ at ]mvps.org> 3/22/2007 1:18:45 PM
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().

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Steffen Grellmann" <anonymous[ at ]anonym.de> wrote in message
news:afn20390joluk8hmv6l3ivhdvnm9o5392g[ at ]4ax.com...
[Quoted Text]
> 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

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net