OL97: Programmatically Accessing Office Form DocumentsLast reviewed: February 27, 1998Article ID: Q168021 |
The information in this article applies to:
SUMMARYThis article provides an overview of how you can use Microsoft Visual Basic Scripting Edition (VBScript) or Microsoft Visual Basic for Applications to programmatically access Office components that are embedded in a Microsoft Outlook 97 Office Form.
MORE INFORMATIONWith Outlook 97, you can create an Office Form that includes an embedded Word document, Excel workbook, Excel chart, or PowerPoint presentation. You typically would use these types of custom Outlook forms as part of a solution that routes Office documents or shares (posts) Office documents in a public folder.
Steps to Create an Office FormTo create an Office form follow these steps:
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/refguide/default.aspNOTE: Because each custom solution has different requirements in order to achieve the desired end result, the methods outlined below are offered as a starting point for achieving the end result, and should be implemented in a way that best suits the solution's needs.
Using Events From Embedded ObjectsWhen using Office Forms to create a custom solution, you may want to have Visual Basic for Applications code in the embedded object automatically run. An example of this is having code automatically calculate dates based on today's date and insert those calculated dates into an embedded Excel spreadsheet. To implement this, you create a Workbook_Open() event procedure in the embedded spreadsheet and use Visual Basic for Applications code to calculate the dates. Because the Workbook_Open() procedure is run automatically when the Office Form opens, the code will execute every time you open the Office Form. NOTE: Word will not execute any auto macros or procedures (typically AutoOpen or Document_Open) when a document is embedded in another program, or container. You can, however, place a CommandButton on the Word document object and create a click event procedure for the CommandButton. The user will have to click the button to run the Visual Basic for Applications code in the Word document. If this workaround is not appropriate for your solution, you can use the GetObject method described below to automate the Word document from VBScript.
Create an Auto Event for an Excel SpreadsheetTo create an auto event for an Excel spreadsheet use these steps:
Using GetObject to Automate an Embedded ObjectThere may be circumstances where you want to use VBScript to put information into the embedded object or set some attributes of the object. An example of this is creating an Item_Open event in VBScript that automatically inserts a list of your contacts and their addresses into a Word Office Form document. You can use the VBScript version 2.0 GetObject method to access the embedded Office documents. The following sample VBScript 2.0 code will automatically insert "This is from VBScript!" into the embedded Word document in a Word Office Form. Because the code is in an Item_Open event, the code runs automatically when the Office Form item opens.
Sub Item_Open() Set objWord = GetObject(, "Word.Application") ' Use Word methods to insert some sample text objWord.Selection.TypeText "This is from VBScript!" End SubNOTE: This functionality does not work with VBScript version 3.0 or older versions of VBScript version 3.1. When using the GetObject function with these versions, GetObject will launch another instance of the application instead of using the existing instance. This problem has been fixed in an update to VBScript 3.1 (VBscript.dll version 3.1.0.2430, file date 12/30/97), which is available for download at:
http://www.microsoft.com/scriptingThe following table lists various objects that you can use with the GetObject method to access embedded objects. Once you have a reference to the object, consult the object model documentation for that program to manipulate that type of object.
Form Type Object Name* ----------------------- ----------------------------------------- Word document Word.Application or Word.Document Excel spreadsheet Excel.Application or Excel.Sheet Excel chart Excel.Application or Excel.Chart PowerPoint presentation PowerPoint.Application or PowerPoint.Show * The object you choose depends on which methods and properties of the application's object model you need to use. REFERENCESFor more information on obtaining VBScript version 2.0, please see the following article in the Microsoft Knowledge Base:
Article-ID: Q167138 Title : OL97: General Information About Using VBScript With OutlookFor more information about creating solutions with Microsoft Outlook 97, please see the following articles in the Microsoft Knowledge Base:
Article-ID: Q166368 Title : OL97: How to Get Help Programming with Outlook Article-ID: Q170783 Title : OL97: Q&A: Questions about Customizing or Programming Outlook |
Additional query words: OutSol OutSol97
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |