Hi Hamza,
Do you want to do this inside your add-in, or from outside while automating Excel?
The most ‘correct’ option is probably to use UI Automation to properly simulate the button press.
The UI Automation learning curve is quite steep though. If you’re automating Excel, a tool like “White” can help (https://github.com/TestStack/White).
If you’re trying to do this from inside the add-in, it’s probably better to just call your own method internally.
Suppose you keep track of the ribbon instance, by storing to a static field when it is constructed:
public class MyRibbon : ExcelRibbon
{
public static MyRibbon TheOneRibbon;
public MyRibbon
{
TheOneRibbon = this;
}
public void OnBigButtonPressed(IRibbonControl button) {…}
}
Then you can call this from other code as:
MyRibbon.TheOneRibbon.OnBigButtonPressed(fakeRibbonControl).
The work for you is then just to implements IRibbonControl in your own class, and you only have to do it well enough to make your OnBigButtonPressed method happy.
-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.
I don’t know how you would get hold of the actual control object.
For this purpose you can send in a fake control that implements the interface:
class FakeControl : IRibbonControl
{
public object Context { get; private set; }
public string Id { get; private set; }
public string Tag { get; private set; }
public FakeControl(string id, string tag)
{
Id = id;
Tag = tag;
}
}
I don’t know of a way to ask Excel for the Id or Tag of a button, so you have to manage this information yourself.
-Govert
From: exce...@googlegroups.com [mailto:exce...@googlegroups.com] On Behalf Of Hamza Nouri
Sent: 14 June 2016 13:43
To: Excel-DNA <exce...@googlegroups.com>
--