This sample add-in demonstrates how to store your own binary data in a worksheet using hidden named ranges that are accessible only to the programmer.
The sample displays the following features:
The following steps were significant in creating and completing the application.
BOOL CBinaryDataApp::OnXllOpenEx() { // Set an event handler to be called whenever a new // workbook is created SetComEventHandler(EVT_NEWWORKBOOK, "BinOnNewWorkbook"); SetSinkEvents(TRUE); ... }
The add-in also contains 2 worksheet functions, BinGetOriginalName and BinGetOriginalName2. These two functions call CXllApp::GetBinaryName in an attempt to retrieve the contents of the BinaryName "OriginalName". Both functions fail in different ways.
BinGetOriginalName calls CXllApp::GetBinaryName without passing a workbook or sheet name. Consequently, the function looks for the value in the active sheet of the active workbook, rather than in the worksheet containing the cell which called the function. This behavior means that the function will return arbitrarily different values, depending on the state of EXcel at the time, making it it pretty much useless.
The second function, BinGetOriginalName2, passes a workbook and sheet name to CXllApp::GetBinaryName. This call usually fails, because it requires Excel to activate a different book and/or sheet, which is illegal during a worksheet function.
These notes should make the developer wary of using BinaryName data within worksheet functions.
If you are using MS Developer Studio 6, then you should open the project file BinaryData.dsp.
If you are using MS Visual Studio .NET 2002, then you should open the solution file BinaryData.sln or the project file BinaryData.vcproj.
If you are using MS Visual Studio .NET 2003, then you should open the solution file BinaryData71.sln or the project file BinaryData71.vcproj.
If you are using MS Visual Studio 2005, then you should open the solution file BinaryData8.sln or the project file BinaryData8.vcproj.