Quantcast
Channel: NetOffice - MS Office in .NET
Viewing all articles
Browse latest Browse all 1741

New Post: Identify workbooks after WorkbookActivateEvent

$
0
0
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;
    }
}

Viewing all articles
Browse latest Browse all 1741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>