Add Collection to Combo Box

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

Add Collection to Combo Box
 
Jeremy McClanathan




Posts: 10
Joined: 2017-02-09
Hello,
I have built a test ribbon with a combobox and I would like to add a custom collect of items to choose from. Specifically, I would like to display the open workbooks to choose from. I can use the ADX Collection Editor to create a list of items to choose from, but where can I put code to add my own collection without using the ADX Collection Editor.
Thank you!
Jeremy
Posted 20 Feb, 2017 10:10:56 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Jeremy,

private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed) {
    this.adxRibbonComboBox1.Items.Clear();
    Excel.Workbooks wbks = ExcelApp.Workbooks;
    Excel.Workbook wbk = null;
    for (int i = 1; i <= wbks.Count; i++) {
        wbk = wbks[i];
        AddinExpress.MSO.ADXRibbonItem item = new ADXRibbonItem(this.components);
        this.adxRibbonComboBox1.Items.Add(item);
        item.Caption = wbk.FullName;
        Marshal.ReleaseComObject(wbk);
    }
    Marshal.ReleaseComObject(wbks);
}


I use this code in the Click event of a Ribbon button. You can use it whenever required. If you need to use it in NewWorkbook or WorkbookOpen, I would check if the code lists the workbooks correctly.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 21 Feb, 2017 03:06:40 Top
Jeremy McClanathan




Posts: 10
Joined: 2017-02-09
Thank you Andrei. I would like to list all open workbooks of all open instances of Excel. In another post you said
A COM add-in should only use the Application object that Office passes to it at startup
Does that mean that a COM add-in cannot get the open workbooks of other open instances of Excel, or is it possible to get all open workbooks?
Thanks!
Jeremy
Posted 23 Feb, 2017 01:39:01 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Jeremy,

I believe you won't be able to start the second Excel instance without using some hack.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Feb, 2017 02:00:05 Top
Jeremy McClanathan




Posts: 10
Joined: 2017-02-09
Thank you,
Is there an event that I can tie this to so the list of open workbooks is always available to the user? For example, when the Add-In ribbon is selected, or the combobox list button is pushed, the list of open workbooks is automatically generated?
Jeremy
Posted 24 Feb, 2017 01:43:09 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hello Jeremy,

You need to regenerate the list of workbooks in every Excel event which is triggered when the list of workbooks is changed; check the events provided by the Excel Events component (ADXExcelAppEvents).

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Feb, 2017 02:33:54 Top