Microsoft Word and Excel 2003 and Code Behind
Microsoft and eBay Integration is based on using Word and Excel 2003's support for code in .NET assemblies to call a .NET library such as the eBay SDK. This capability is different than the VBA environment available directly from Tools menu in the various office products. Though the VBA environment is still available, you may want to consider the Visual Studio .NET environment.
There are several reasons to use Visual Studio.NET to create the code that operates your document or spreadsheet:
- Performance: You can use the more structured languages like VB.NET and C#. Having these strongly typed environments helps eliminate a whole class of syntax errors.
- Familiarity: If you code in Visual Studio.NET most of the time, then you'll be in familiar territory and more productive. An interactive debugging environment, context based help, and other facilities are available.
- Portability: You can easily incorporate functionality from existing code into your document or spreadsheet. If you already have a routine that does something you need, you can just reference the assembly.
- Security: Your code is deployed in a managed DLL that does not have a source format, and you can control access to the DLL using .NET's security mechanism.
Speaking of security, this is one area that can frustrate some developers new to .NET and Office Code Behind. .NET provides security mechanisms that go far beyond simple file permission. These mechanisms allow the developer or security administrator to specify which .NET assemblies may be accessed by applications. Because of this, you may receive messages stating that your application was unable to acquire execute access to assemblies such as the eBay SDK. If so, you need to define access for the appropriate assemblies in Microsoft .NET configuration tool (found under Start|Control Panel|Administrative Tools
). Microsoft has several tutorials
on this tool on their Web site
To facilitate developing in Visual Studio.NET, Microsoft has developed an add-on to the Visual Studio environment called "Visual Studio Tools for the Microsoft Office System." This add-on modifies your Visual Studio environment to contain several new projects. These projects contain options for creating Word and Excel applications in either VB.NET or C#.
When you generate a Word project, Visual Studio will create three files:
The eBay Search Document
- AssemblyInfo contains all of the basic settings for the assembly. You will probably not need to change these settings.
- A Word document. This document is given the name of your project. You can modify it by adding text or controls.
- ThisDocument.cs (or .vb if you used VB.NET) contains the event handlers associated with the Word document. The generated version of the file contains handlers for the document's open and close events. You can add additional events as necessary. ThisDocument.cs is where your code will likely reside.
Many of the examples for using the API and SDK focus on the sale of items on eBay (see "Integrate Your Inventory System with the eBay SDK
"). While many people sell things on eBay, buyers are stronger in number and they can also benefit from the using the SDK. To this end, this article's sample app is a search application uses Office and the eBay SDK.
This sample app is fairly simple. The user enters some search criteria and gets back a listing of the items that matched the criteria. In order to be able to include this listing in multiple documents, the app is written in Word 2003.