Version 17 of How one discovers the API for a COM-exporting application

Updated 2004-08-15 18:15:36

One place to start is by Googling "$app_name object model". The (full) help for most Microsoft applications includes this information, often disguised as instructions on use of Visual Basic for Applications or VBScript. These reference guides usually are not installed by default during the typical installation. They can be added later by rerunning the setup program with the custom install option. Also, one can often start the application in question, and select Tools/Macros/Visual Basic Editor, then View/$app Explorer, and the API should be within a click or two more. This process is documented in Microsoft's knowledgebase. [L1 ]

You can also record a macro and then examine the code.

To record a macro

  • On the Tools menu, point to Macro and click Record New Macro.
  • Type a name for the new macro in the Macro name box and click OK.
  • Perform the actions you want to learn more about.
  • When you have completed the actions you want to record, on the Stop Recording toolbar click Stop Recording.

To view a recorded macro

  • On the Tools menu, point to Macro and click Macros .
  • Find and click to select your recorded macro in the list of available macros.
  • Click Edit.

Also, Chin Huang notes, "you can consult the MSDN library at http://msdn.microsoft.com/library/default.asp In the left tree, open Office Solutions Development -> Microsoft Office -> Microsoft Office 2000 -> Microsoft Office 2000 Language Reference -> Microsoft Excel 2000 Reference."


How to Obtain Built-In Constant Values for an Office Application

The article http://support.microsoft.com/support/kb/articles/Q239/9/30.ASP describes how to obtain the constant values for Office applications from type library files. Here's an example of how to do it in Tcl.

Load the tcom extension.

    % package require tcom
    3.8

Read the type library file.

    % ::tcom::import $pathToOfficeDirectory/excel9.olb
    Excel

The ::tcom::import command put the constant values into some arrays. It returns the namespace where it created the arrays.

    % info vars ::Excel::*
    (many array names listed)
    % parray ::Excel::XlRowCol
    ::Excel::XlRowCol(xlColumns) = 2
    ::Excel::XlRowCol(xlRows)    = 1

By using optcl you can browse the interfaces of loaded com objects with:

 package require optcl
 tlview::refview .ref
 tlview::loadedlibs .libs

LES on April 28, 2004: optcl tells me that tlview::refview is an invalid command. ???

CL on 6 August 2004: optcl, and [refview] in particular, are doing great things for me, although I still have a lot to learn.

On the 13th, CL observes that it ought to be a nice project to rewrite these in tcom, mainly in recognition that the latter is more widely deployed.


http://www.mvps.org/skp/vba.htm has examples of VBA controlling PowerPoint.


phk Sometimes an object browser can help.

  • ObjectScope [L2 ]
  • OleView (OLE Object Viewer): included in both MS Visual Studio and the Platform SDK
  • Visual Basic Object Browser: part of the Visual Basic environment.
  • application specific e.g. Word VisualBasic-Editor > Object Catalog

[... Open MS Word and press ALT + F11 (for the VBA environment), then F2 (for the object browser) ...]