How do you access Ribbon controls (eg. RibbonEditBox) from outside class?

1.2k views Asked by At

I have a Ribbon1 class which was created by the Visual Studio.

public Microsoft.Office.Tools.Ribbon.RibbonEditBox IDBox;

I would like to access one of the ribbon controls from within a different class.

using MyRibbon = ExcelAddIn1.Ribbon1;

xlTextID = MyRibbon.IDBox.Text;

I got the error message.

An object reference is required for non-static field, method, property.

I can't make IDBox static because it's initialized as an instance of a class via 'InitializeComponent()' method.

this.IDBox = this.Factory.CreateRibbonEditBox();

I have also tried to create a property.

    private Microsoft.Office.Tools.Ribbon.RibbonEditBox IDBox;

    public Microsoft.Office.Tools.Ribbon.RibbonEditBox IDBoxProperty
    {
        get { return IDBox; }
        set { IDBox = value; }
    }

Doing this I have seen exactly the same error.

How can I keep IDBox non-static and still access it from outside class?

I can found the answer - see it below.

1

There are 1 answers

0
LLaP On BEST ANSWER

Instances of the all Ribbon controls derived from Microsoft.Office.Tools.Ribbon can be accessed via Globals.Ribbons.Ribbon1.

Therefore, in order to access public Microsoft.Office.Tools.Ribbon.RibbonEditBox IDBox; which is created by InitializeComponent()method, you would do Globals.Ribbons.Ribbon1.IDBox.

More information about accessing Ribbon Controls at Run-Time:

https://msdn.microsoft.com/en-us/library/bb772088.aspx