none
How to access application object from Ribbon click event RRS feed

  • Question

  • Hi,

     I am developing a word addin by extending IDTExtensibility2 object. Here i created the ribbon and it has the button with onaction. Once the button is pressed the onaction method is triggered and it has signature of public void onClick(IRibbonControl control).

    But here my issue is, how do i access word application object from click event. is it IRibbonControl.context ? If so it coming null when no document available and we try to create a new document.

    This is working perfect with word 2003.. all I was doing is, commandbarbutton.Application..

    Please suggest....


    Thanks Sameer Kamarudeen
    Friday, September 9, 2011 2:37 PM

Answers

  • I got it....

    Initialize a static variable and from onConnection method initialize it.. so that can be  use every where...

    No way from IRibbon control....

     


    Thanks Sameer Kamarudeen
    Friday, September 9, 2011 5:50 PM

All replies

  • Hello,

    IRibbonControl.Context creates a COM object representing the window in which the event was triggered; you cast IRibbonControl.Context to Excel.Workbook, Word.Document, Outlook.Inspector, etc and then you access the Application property of the object.


    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    • Proposed as answer by Andrei Smolin Friday, September 9, 2011 3:07 PM
    • Unproposed as answer by Andrei Smolin Friday, September 9, 2011 3:07 PM
    Friday, September 9, 2011 3:00 PM
  • Hi Andrei,

     I tried it..below line is my code..

    Microsoft.Office.Interop.Word.Document currentDocument = control.Context as Microsoft.Office.Interop.Word.Document;

    but it gives null cor document.

    but the below code works...

    Microsoft.Office.Interop.Word.Application currentApplication = (control.Context as Microsoft.Office.Interop.Word.Window).Application;

    in this case the currentApplication will be null when no document available in word....

     


    Thanks Sameer Kamarudeen
    • Proposed as answer by Andrei Smolin Friday, September 9, 2011 3:07 PM
    Friday, September 9, 2011 3:04 PM
  • My fault! You are absolutely correct!
    Regards from Belarus (GMT + 2),

    Andrei Smolin
    Add-in Express Team Leader
    Friday, September 9, 2011 3:07 PM
  • I got it....

    Initialize a static variable and from onConnection method initialize it.. so that can be  use every where...

    No way from IRibbon control....

     


    Thanks Sameer Kamarudeen
    Friday, September 9, 2011 5:50 PM