VSTO: Why is OfficeRibbon.Context null?

I am developing my first Word 2007 addin, and I added OfficeRibbon to my project. In the mouse click handler, I need a link to either the current Word.Documentone or Word.Application.

I am trying to get a link through a property OfficeRibbon.Contextthat, according to the documentation, should reference the current object Application. However, he is always null.

Does anyone know or

a) if there is something that I need to do to make the OfficeRibbon.Contextdisplayed correctly populated?
b) if there is any other way, can I get a link to a Word Application or an active Word document?

Notes:

  • I am using VS2008 SP1

  • The ribbon looks as if it was initialized perfectly: the ribbon displays correctly in Word; I can configure the debugger using both the constructor and the OnLoad elements; Mouse button handlers execute correctly.

  • Here is online help for this property ;

OfficeRibbon.Context Property

C#
public Object Context { get; internal set; }

An object that represents the inspector window or application instance associated with this OfficeRibbon object.

Notes

In Outlook, this property refers to the Inspector window in which this OfficeRibbon is displayed.

In Excel, Word, and PowerPoint, this property returns the application instance in which this OfficeRibbon is displayed.

+3
source share
4 answers

Excel 2007 AddIn VS2008 SP1. , , , internal static AddIn, :

public partial class ThisAddIn
{
    internal static Application Context { get; private set; }

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        Context = Application;
    }
    ...
}

public partial class MyRibbon : OfficeRibbon
{
    private void button1_Click(object sender, RibbonControlEventArgs e)
    {
        DoStuffWithApplication(ThisAddIn.Context);
    }
    ...
}
+4

:

Globals.ThisDocument.[some item]

MSDN

+2

Get it from:

Globals.ThisAddIn.Application

+2
source

Although I am not very versed in changes to the Word 2007 text model, here is my explanation using VBA knowledge.

The application is a globally accessible object. In addition, Application.ActiveDocument should force you to process the current document.

Speculation: how are you trying to add a feed?

+1
source

Source: https://habr.com/ru/post/1698963/


All Articles