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.
Instances of the all Ribbon controls derived from
Microsoft.Office.Tools.Ribbon
can be accessed viaGlobals.Ribbons.Ribbon1
.Therefore, in order to access
public Microsoft.Office.Tools.Ribbon.RibbonEditBox IDBox;
which is created byInitializeComponent()
method, you would doGlobals.Ribbons.Ribbon1.IDBox
.More information about accessing Ribbon Controls at Run-Time:
https://msdn.microsoft.com/en-us/library/bb772088.aspx