Getting UI handle from AddInModule

Add-in Express™ Support Service
That's what is more important than anything else

Getting UI handle from AddInModule
Wanted to get handle for Winform UI from AddInModule  
Madhur Tiwari




Posts: 6
Joined: 2016-04-18
Launching Winform UI from ribbon button and on clicking a button on UI wanted to provide handle to AddinModule. private void cbbPMDRibbonButton_OnClick(object sender, IRibbonControl control, bool pressed)
{
if (_frm == null)
{
_frm = new AddInMainUI();
_frm.FormClosed += instanceHasBeenClosed;
}
_frm.Show();
PublishApplication();
}

In VSTO version, I was getting from Ribbon class that was having UI instance gas property.
frm = _ribbon.AddInMainUI;

Now, how do I get from Addin express?
Posted 18 Apr, 2016 13:59:28 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Madhur,

To access the add-in module from another class, you use this construct: {add-in project name e.g. Addin1}.AddinModule.CurrentInstance.

Is this what you are looking for?


Andrei Smolin
Add-in Express Team Leader
Posted 19 Apr, 2016 05:03:12 Top
Madhur Tiwari




Posts: 6
Joined: 2016-04-18
Thanks Andrei for response,
private void cbbPMDRibbonButton_OnClick(object sender, IRibbonControl control, bool pressed)
{
Microsoft.Office.Interop.Excel.Workbook doc = (HostApplication as Excel._Application).ThisWorkbook; <== This throws null exception
--
--
}

Whole objective is to launch winform UI and that uses host (excel,word/ppt/outlook docs properties)..
Using VSTO getting following way.. in addin

Microsoft.Office.Interop.Excel.Workbook doc = Globals.PMDAddIn.Application.ActiveWorkbook;

and form instance is coming from ribbon control that exposes winform UI as property.
frm = _ribbon.ContributionForm;

Can you please give one example/sample that does something like this?
Posted 22 Apr, 2016 09:23:11 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Madhur,

Replace (HostApplication as Excel._Application).ThisWorkbook with (HostApplication as Excel._Application).ActiveWorkbook. Is this what you are looking for?


Andrei Smolin
Add-in Express Team Leader
Posted 22 Apr, 2016 09:40:41 Top
Madhur Tiwari




Posts: 6
Joined: 2016-04-18
Yes, Andrei, this returns proper object. Is there any sample app where addin launches and .NET UI app and interacts with event handling etc..I have more to do, earlier using Ribbon object under VSTO able to interact.
Posted 22 Apr, 2016 09:57:45 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Madhur,

Do you mean events of office applications or Ribbon controls?
Posted 22 Apr, 2016 10:18:28 Top
Madhur Tiwari




Posts: 6
Joined: 2016-04-18
Thanks Sergey, Any AddIn Sample that launches .NET UI (e.g. Winform) and then this UI interacts with Host application (e.g. excel, word etc) and then it communicates both way using Callback functions either ribbon control or directly.
Posted 22 Apr, 2016 10:24:07 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Madhur,

Please download the example project here:
https://www.add-in-express.com/projects/temp/myaddin256.zip
Let me know if you need anything else.
Posted 25 Apr, 2016 04:49:00 Top