This project has moved. For the latest updates, please go here.

Identify workbooks after WorkbookActivateEvent

Jun 17, 2014 at 7:48 PM
Edited Jun 17, 2014 at 7:49 PM
Hi Sebastian,

First off huge thanks for NetOffice! Extrmely good stuff!

I want to store extra data about workbooks, and select the right data when a user selects another workbook (to load into a taskpane). I have this code, but if I have two workbooks open and switch between then a couple of times, they get added to the List again every time, it seems the Wb reference points to a different object every time (some wrapper?).

Is there a way to uniquely identify a workbook after the WorkbookActivateEvent (Preferably without having to use the name as it may change) ?
XL.WorkbookActivateEvent += XL_WorkbookActivateEvent;
and handler:
List<Workbook> _workbooks = new List<Workbook>();

void XL_WorkbookActivateEvent(Workbook Wb) {
    if (!_workbooks.Contains(Wb)) { 
        // reference seem different every time event is fired
        _workbooks.Add(Wb);
        Wb.SheetChangeEvent += Wb_SheetChangeEvent;
    }
}