This documentation is archived and is not being maintained.

Working with the Microsoft Script Editor

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The Microsoft Script Editor is provided in the Microsoft® Office XP applications, so you can work with the HTML code, DHTML objects, and script in an Office document from within an Office application. To open the Script Editor, point to Macro on the Tools menu, and then click Microsoft Script Editor.

Note   The Microsoft Script Editor is not used in Microsoft® Outlook®. To work with script in Outlook, you use the Outlook Script Editor.

The Script Editor was designed to work much like the Visual Basic Editor. Unlike the Visual Basic Editor, there is a single instance of the Script Editor open at one time, which means that you can use the Script Editor's Project Explorer to access every open Office document that also has the Script Editor open.

When you view an Office document in the Script Editor, you will see the HTML and Extensible Markup Language (XML) code that constitute the Office document when it is rendered as a Web page.

Understanding XML Code in Office Documents

When you view an Office document in the Script Editor or any other HTML editor, you might see a great deal of information you do not recognize as part of a typical HTML document. Most likely, you are looking at the XML elements the Office application has added to the document. You can identify the XML code in an Office document as the information between the <XML> tags.

The XML data that appears by default in an Office document depends on the application used to create the document. In Microsoft® Excel, Microsoft® PowerPoint®, and Microsoft® Word, the XML data is used to preserve document-specific information, such as document properties or option settings, so that the page can be accurately rendered as an Office document when it is opened in an Office application. In a Microsoft® Access data access page, XML data is used to supply data to the hidden Microsoft Office Data Source control (MSODSC). It should never be necessary for you to manipulate the XML code that appears in an Office document when it is viewed in an HTML editor.

Caution   You should never manipulate the XML code associated with a Data Source control in an Access data access page.

Understanding the Script Editor's User Environment

In the Script Editor, you work with the HTML code and script in an Office document by using the Source tab at the bottom of the editor window.

Note   The Script Editor also displays a Design tab, but Design view is not enabled when you are working with an Office document.

The left side of the editor window makes it possible for you to access a toolbox, and a Document Outline window. As when you are working with UserForms in the Visual Basic Editor, you use the toolbox in the Script Editor to add controls to the HTML code in the page. To see the hierarchy of HTML objects on a page and the various DHTML objects in a document, you use the Document Outline window. Much like the Visual Basic Editor, the Script Editor's Source view includes a color-coded view of the HTML code in a document along with drop-down lists that display the available objects and their related methods and properties.

Note   For complete documentation about the Script Editor's user environment, click Contents on the Help menu in the Script Editor.

Using the Script Editor to Add Event Procedures

The Document Outline window makes it easy to add event procedures to an Office document. For example, to add an event procedure for the document object's onClick event, click the "+" sign next to the document object in the Script Outline window and then double-click onClick. The Script Editor inserts a VBScript <SCRIPT> block in the document and adds the onClick event procedure.

There is one very important difference between what happens when you use the Script Editor to add event procedures and what happens when you use the Visual Basic Editor to add event procedures to Office documents: The Script Editor does not add the parentheses or the required arguments (if any) at the end of the event procedures.

For event procedures that do not require arguments, the absence of the empty parentheses does not prevent the script from running when the page is viewed in a browser. However, for event procedures that do require arguments, their absence prevents the script from running even if the code in the procedure does not use the missing arguments. If you are unaware of this, the missing arguments can cause you some headaches when you are trying to debug your script.

It is up to you do determine which event procedures require additional arguments and what those arguments are. When you determine this information, you add the arguments by hand. You can find complete documentation for an event procedure related to an object in that object's Help file or by using the Object Browser. The following event procedure for the Spreadsheet control's Calculate event is an example of an event procedure that requires an argument that is not added by the Script Editor:

Sub Spreadsheet1_Calculate(EventInfo)
   document.all("txtTotal").value = formatNumber(document _
      .all("Spreadsheet1").Range("A7").value, 2, TristateTrue, TristateTrue)
End Sub

The parentheses and the EventInfo argument in the preceding example were added by hand. The argument information was obtained by viewing the Help topic for the Calculate event in the Spreadsheet control's Help file. In this example, EventInfo is the actual name for the argument as it appears in the Help file, but this argument could have been named anything. You are not required to use the same name for an argument as long as there are placeholders provided for each argument.

See Also

Working with Office Web Discussions Client | Enabling Discussions | Understanding the Global Object | Understanding Discussion Servers | Understanding Discussions | Understanding Subscriptions | Understanding Office Objects and Object Models