Where can I find the object model documentation?The object models for the Office applications are documented in a Language Reference for both versions of Office: Microsoft Office 97 Visual Basic for Applications Language Reference
Microsoft Office 2000 Visual Basic for Applications Language Reference
The Language References are available on the MSDN and in the online Help that ships with Microsoft Office. They can also be purchased in printed form. For ordering information, please visit:
The following table lists the Help files for each Office application.
|Application||Version 97 (or 8.0)||Version 2000 (or 9.0)||Version 2002 (or 10)||Version 2003 (or 11)|
|MapPoint||N/A||Mappoint.chm (ver.2001)||Mappoint.chm||MAPPOINT.chmn (Ver. 2004)|
|FrontPage||N/A||Vbafp4.chm, Vbafpom4.chm||Vbafpd10.chm, vbafpw10.chm||VBAFPD10.chm, VBAFPW10.chm|
The Help files that ship with Microsoft Office 97 are installed by default at:
How can I use the object model documentation?There are several methods you could use to find documentation for a specific class, method, or property:
- Search the VBA Help File:
In the Visual Basic Editor for the Office application, click Contents and Index on the Help menu. On the Contents tab, select the language reference you want and click Display. The VBA Help for the Language Reference you selected appears. At this point, you can use either the Index or the Find tab to locate information on a specific class, method, or property.
- Use Context Sensitive Help in a Module or in the Immediate Pane:
In the Visual Basic Editor for the Office application, type the class, method, or property in the code window of a module or in the Immediate Window, highlight the text and press the F1 key. The Help topic for the item appears.
- Use the Object Browser:
Press the F2 key in the Visual Basic Editor for the Office application to display the Object Browser. The Object Browser lists all the classes the application exposes and the methods or properties associated with each class. To view Help on a specific class or class member, select it in the Object Browser and press the F1 key.
How do I know which classes, methods, and properties to use?If you are not already familiar with the object model of the application you intend to automate, you can use the application's Macro Recorder to get an idea. To illustrate, suppose you want to automate Microsoft Word to add some text to a new document and then save the document but you don't know which methods and properties to use; you can start with the Macro Recorder:
- Start Microsoft Word.
- Click Macro on the Tools menu and then select Record New Macro. Make note of the new macro's name and click OK to start recording.
- Start a new document.
- Type one and press the ENTER key.
- Type two and press the ENTER key.
- Type three.
- Click Save on the File menu and save the document as "C:\doc1.doc."
- Click the Stop Recording button (or click Macro on the Tools menu and select Stop Recording).
- To view the VBA code that the Macro Recorder generated from your actions, click Macro on the Tools menu and select Macros. Select the name of the new macro in the list and click Edit. The Visual Basic Editor appears with the recorded macro:
ActiveDocument.SaveAs FileName:="Doc1.doc", FileFormat:=wdFormatDocument,_
LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, _
SaveFormsData:=False, SaveAsAOCELetter:= False
Start with examining the first line of the recorded macro: Documents.Add. Highlight Documents on the code module for the Recorded macro and press the F1 key. The Help topic provides you with the following important information:
- The "Documents Property" returns a Documents collection that represents all the open documents.
- The "Documents Property" applies to the Application object.
- The "Add Method" adds a new, empty document to the collection of open documents.
- The "Add Method" can take two arguments, both of which are optional.
- The "Selection Property" returns the Selection object that represents a selected range or the insertion point.
- The "Selection Property" applies to the Application object.
- The "TypeText Method" inserts the specified text.
- The "TypeText Method" has one required argument of type String.
- The "TypeText Method" applies to the Selection Object.
- The "TypeParagraph Method" inserts a new blank paragraph.
- The "TypeParagraph Method" applies to the Selection Object and has no arguments.
- The "ActiveDocument property" returns a Document object representing the document with the focus. "ActiveDocument" applies to the Application object.
- The "SaveAs method" saves a document. Depending on the version of Word, this method has from 11 to 16 arguments, only one of which is required. "SaveAs" applies to a Document object.
Upon examination of the recorded macro, you see that the SaveAs method has an argument for which it passes the built-in constant wdFormatDocument. Depending on the programming language you choose for your automation controller, you might need to pass the numeric value for the built-in constants. The Help topic for the SaveAs method does not give this information but you can find it in the Object Browser. Press the F2 key to display the Object Browser. Type:
in the search window and press the ENTER key. In the bottom pane of the Object Browser, you see the numeric equivalent of wdFormatDocument(=0) as well as other information about the constant.
Where can I find some automation code samples?
The information presented so far gives you good groundwork for writing automation code. The Microsoft Knowledge Base is an excellent resource for finding automation code samples written in Visual Basic, Visual C++ and MFC. Here are just a few:
For Visual Basic developersFor more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
Visual C++ developers (using MFC)For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
C/C++ developers (without MFC)For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
Visual J++ developersFor more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
Visual FoxPro developersFor more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
ID articolo: 222101 - Ultima revisione: 22 set 2009 - Revisione: 1