Workbook unique identifier

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

Workbook unique identifier
 
Vladimir Vajda




Posts: 75
Joined: 2011-05-24
I have some dictionary of workbooks currently opened in excel. But I have problem with key. I used workbook.FullName for key earlier since this is unique property with which I can identify particular workbook. But when user opens new workbook its name is Book1. And when it save it its name changes to something else and I cannot find it anymore in my dictionary. I cannot use beforeSave event either because user can easily click on cancel button on prompted dialog and cancel saving where beforeSave event is already fired, and also there is no information about new name of workbook being saved. I'm searching for some property (e.g. GUID, ID) which is of primitive type and will uniquely idenfity workbook. Can I use Equals method for this or maybe GetHashCode or something third?
Any suggestion?

best regards,
Vladimir Vajda
Posted 23 May, 2012 06:55:20 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Hi Vladimir,

For a new unsaved workbook, your add-in can intercept WorkbookBeforeSave and show the Save/SaveAs dialog e.g. via Excel.Application.GetSaveAsFilename(). And if you use Excel 2010 only, then it provides the WorkbookAfterSave event.

Alternatively, you can add a custom property to the Workbook.CustomDocumentProperties collection (of the Office.DocumentProperties type). This way is simpler. But there's a way to see the property and its value in the Office UI.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 May, 2012 07:21:01 Top
Vladimir Vajda




Posts: 75
Joined: 2011-05-24
Thanks Adndrei,

I think I'll do it with custom properties.
Posted 24 May, 2012 00:07:28 Top
Andrei Smolin


Add-in Express team


Posts: 14094
Joined: 2006-05-11
Good luck!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 May, 2012 03:16:06 Top