Category Archives: .NET

Capture Excel Workbook Close, Worksheet Delete, Worksheet Rename Events

I created a C# class to handle some of missing Excel application level events such as : Workbook close, worksheet rename, worksheet delete, range name added, range name deleted, application activated, application deactivated.

Excel does offer a workbook closing event, but the user can cancel it. The workbook closed event fires when the workbook actually closes.

Usage is fairly straightforward :

ExcelApplicationEvents _appEvents = 
new ExcelApplicationEvents(_app, 
ApplicationEvents.WorkbookClosed);

_appEvents.WorkbookClosed += 
_appEvents_WorkbookClosed;

Read Write Binary Data in VBA and .NET

I created VBA and .NET classes to read and write binary data (blobs).

Longs, strings and byte arrays can be written to a single byte array using the VBA class, written to a file, then read by the .NET version (and vice-versa).

These classes can be extended to use a file format structure that includes metadata about the data included in the blob (Zip file format for example) – but I will leave that up to the reader.

Without file format metadata, you will have to know ahead of time the data type included in the blob and read/write in the correct order.

Download VBA and .NET classes here.

Extract VBA From XLSM and XLAM Excel Workbooks

I created a C# .NET class to extract VBA from XLSM and XLAM Excel workbooks – even if password protected. I used Mirosoft’s Open XML SDK 2.5 to read a workbook’s VbaProjectPart stream. From the bin stream I extract the VBA source code using Structured Storage API’s.

Microsoft’s Office VBA File Format Structure Reference

I have even been able to retrieve VBA from corrupted workbooks that won’t even open in Excel. See the class in action here.

Extract VBA From XLSM and XLAM Excel Workbooks
Extract VBA Source Code From XLSM and XLAM Excel Workbooks