Defining the Workbook Connection
There's one last task to accomplish before you can use even the simple DLL described in this article. You must create a connection between the workbook and the DLL or Excel will never load it. To perform this task, you must add special entries to the workbook properties. Simply use the File | Properties command to display the workbook Properties dialog box. Select the Custom tab.
You must make two custom entries to load the DLL. The first describes the location of the file. Type
_AssemblyLocation0 in the Name field and the DLL location in the Value field. Use a relative location to make it easier to move the workbook to another location. For example, my assembly is located in the .\SimpleMessage_bin folder. Click Add when you complete the entry.
The second custom entry describes the name of the assembly without the file extension. Type
_AssemblyName0 in the Name field and the DLL name in the Value field. Click Add again when you complete the entry.
At this point, you can close Excel and reopen the workbook. The add-on will load. In my case, I saw a message in the upper left corner saying the add-on had started.
Putting it All Together
This is a very short introduction to a much longer process for most developers, but you now have the tools to work with Office 2003 through Visual Studio without spending a lot of cash to do it.
Essentially, you need to perform four tasks. First, create your project and Office references using the COM, not the .NET technique. Yes, you'll still end up using those .NET modules listing in the \Windows\assembly folder, but not directly. Second, write code that includes the required
_Startup() method, and a
_Shutdown() method. You can add as much additional code as you like, but every DLL must contain these three elements. Third, create a folder for your DLL and set security on
it. Fourth, add the two custom properties to the document (workbook, Word file, Access database, whatever) to create a connection between the document and your DLL.
The one word of warning I can provide is start slow. Build your application with care because even with the Microsoft supplied debugging techniques, you'll find it difficult to troubleshoot an add-on that grows too quickly. I've seen a few developers put relatively complex DLLs together, but the successful add-ons were built one step at a time.
John Mueller is a freelance author and technical editor. He has writing in his blood, having produced 63 books and over 300 articles to date. The topics range from networking to artificial intelligence and from database management to heads down programming. His most recent book is Mining Google Web Services (Sybex, ISBN: 0782143334). His technical editing skills have helped over 35 authors refine the content of their manuscripts. You can reach John by E-mail or his Web site.