Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > Fire menuitem click event programmatically
 

Fire menuitem click event programmatically

Hi,

Please let me know, how to fire the click event of a Excel 2007 menu item programmatically in C#.

I have looped through the Menubars collection, Menu collections and MenuItems collections to identify the MenuItem of interest.

My requirement is to provide some specific buttons in my custom ribbon, which has identical behavior with some of Excel 2007 menu items.

I am using VST0 3.0 SP1 with .NET 3.5
Aritra Saha  Thursday, October 15, 2009 2:10 PM
Hi Anitra

Is this a CommandBarButton, or a button in the Ribbon? These are two quite different things, when it comes to the object model.

If, as you say, you've managed to "identify the Office.CommandBarButton", please show us how you are doing so. That will help us understand what it is we're dealing with.

If you have a CommandBarButton object, you should be able to use that object's Execute method to "click" it.
Cindy Meister, VSTO/Word MVP
  • Marked As Answer byAritra Saha Friday, October 16, 2009 12:44 AM
  •  
Cindy Meister  Thursday, October 15, 2009 3:54 PM
Take a look at ExecuteMso API (http://msdn.microsoft.com/en-us/library/aa434602.aspx)
I am sure there is a lot of example on the web how this can be used.
Misha
Misha Shneerson - MSFT  Thursday, October 15, 2009 2:43 PM
Thanks for the reply.

In my case, its actually a 3rd party component button, whose click event I need to fire. So, I cant retrieve the IdMso.

I have also managed to identify the Office.CommandBarButton for the button whose click event I need ti trigger.

Is there some way, I can trigger the click event of the CommandBarButton which I have identified. I can find there are some methods: accDoDefaultAction.

Please let me know, how this can be achieved.
Aritra Saha  Thursday, October 15, 2009 3:10 PM
Hi Anitra

Is this a CommandBarButton, or a button in the Ribbon? These are two quite different things, when it comes to the object model.

If, as you say, you've managed to "identify the Office.CommandBarButton", please show us how you are doing so. That will help us understand what it is we're dealing with.

If you have a CommandBarButton object, you should be able to use that object's Execute method to "click" it.
Cindy Meister, VSTO/Word MVP
  • Marked As Answer byAritra Saha Friday, October 16, 2009 12:44 AM
  •  
Cindy Meister  Thursday, October 15, 2009 3:54 PM
Thanks for the reply.

The Execute() method worked in my scenario
Aritra Saha  Friday, October 16, 2009 12:44 AM

You can use google to search for other answers

Custom Search

More Threads

• How to store the mail items
• How do I make Bookmark visible in Word 2007 ?
• Reading cells from Excel filled by DDE calls.
• Testing if a user property exists
• Render HTML in email body
• XMLNode and attached Schema navigation
• Get the current user email id in outlook 2003 using vb.net 2005
• Preventing Keystrokes using Low Level Keyboard Hooks (it works, but....)
• Get Data from a Word document
• Word Automation works too slow