Microsoft Office 2000/Visual Basic Programmer's Guide |
Even if you are an experienced Office and VBA developer, you might approach this subject with a little apprehension. If you have no experience with using DHTML or adding script to Web pages, this section heading alone may be somewhat intimidating. But there is good news here: Working with Web technologies is remarkably similar to working with Office objects through VBA. Therefore, this chapter provides an introduction to using these Web technologies by building on your existing knowledge of VBA.
Note The sample files that accompany this chapter contain examples of the various tools and techniques discussed in this section and elsewhere in this chapter. To gain additional understanding of how the subjects discussed here apply to Office documents, you should examine the files in the ODETools\V9\Samples\OPG\Samples\CH12 subfolder on the Office 2000 Developer CD-ROM to see how they were built. This chapter also uses a number of the HTML sample files in the ODETools\V9\Samples\OPG\Samples\CH05 subfolder.
DHTML, through the document object model, provides an application programming interface (API) for working with HTML elements and cascading style sheet information. You can write script against the objects on a page to work with the data they contain as well as with their location and appearance. Writing script to manipulate the objects in a Web page is really no different from writing VBA code to manipulate the objects in an Office document.
The document object model supports a data-binding architecture that allows you to programmatically sort or filter data displayed on the page without requiring additional trips to the server. The document object model also supports Microsoft Scripting Components (scriptlets), which are lightweight, reusable objects that encapsulate code or a user-interface component. Scriptlets are created by using HTML code and script (either Microsoft Visual Basic Scripting Edition [VBScript] or Microsoft JScript).
To add script to an Office document, you use the Microsoft Script Editor. To open the Script Editor from inside an Office document, point to Macro on the Tools menu, and then click Microsoft Script Editor. For more information about working with the Script Editor, see "Scripting in Office Applications" later in this chapter.
Although Microsoft Internet Explorer supports the use of VBScript code, JScript code, or both in a Web page, this chapter focuses primarily on working with VBScript code for three reasons:
The only time you may not be able to use VBScript code in a Web page is for code used to detect the type of browser being used to view the page. VBScript code works in all versions of Internet Explorer 3.0 or later. However, VBScript code works in Netscape Navigator only by using a plug-in. Since JScript code runs in both browsers, you will want to write script that detects the browser type in JScript. To see an example of a scriptlet that uses a combination of VBScript and JScript code to return information about the browser being used to view a page, see the BrowserVersion.htm file in the ODETools\V9\Samples\OPG\Samples\CH12 subfolder on the Office 2000 Developer CD-ROM.
Note Many of the techniques discussed in this chapter involve technologies designed to work best with Internet Explorer version 4.01 or later. In particular, some of the DHTML features discussed in this chapter may not be fully functional when they are viewed in another browser. However, the DHTML features discussed here are designed to degrade gracefully when you use a browser that does not fully support all features. Typically, this means that interactive features are inoperable and the content is displayed as static data on the page.
A complete discussion of Web technologies is beyond the scope of this chapter, and these technologies are well documented in other resources. For a list of those resources, see "Where to Go from Here" at the end of this chapter.