2

I'm big into developing with VBA (cuts through corporate red tape with a chainsaw) and have become adroit at extending these macros with various add-in references (IE, Excel, Outlook, and Word automation objects, IE of which is my best 'trick').

Anyway, I'm curious how I could get a list of the OOP 'guts' of a given object on a web page, seeing as my IDE cannot give any hints.

Here's some sample code, make sure shdocvw.dll is referenced, and presume 'www.mywebsite.com' has a username and password text box as well as a button to log in:

Sub MyIEAutomationExample
    Dim IE as InternetExplorer
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate ("http://www.mywebsite.com")

    Do Until IE.ReadyState = READYSTATE_COMPLETE 'Delay for loading page
    Loop

    IE.Document.all.Item("tbxUserName").Value = "Nxwtypx"
    IE.Document.all.Item("tbxPassword").Value = InputBox("Please enter your password.")
    IE.Document.all.Item("btnLogin").Click
End Sub

The question on my mind, is what if I wanted to ascertain the other Properties/Methods/Events of tbxUserName, tbxPassword, or btnLogin? Is there some kind of reference availiable for standard objects?

And even then, what about kinkier objects like Rich Text Boxes, for all I know, that were developed in-house?

Nxwtypx
  • 21
  • 1
  • 4

2 Answers2

1

If it's a standard HTML page you are looking at then the document property of the InternetExplorer object should return an HTMLDocument object. If you add a reference to "Microsoft HTML Object Library" then you can see the object model for HTMLDocument.

Details for individual HTML elements can be found under "HTML" + the element name + "Element". For example, details for button elements are found under HTMLButtonElement

I'm not sure what you can find out about non-standard objects. Remou's suggestion of adding a watch may be the best idea here. You can then use the Watch window to locate the node which corresponds to the non-standard object and see which (if any) properties it exposes.

Finally, if the document you are looking at is in XHTML or XML format then you may want to use XMLHttpRequest (instead of InternetExplorer) as this lets you use a more powerful lanaguage called XPath to locate the nodes you want to examine - see this answer to a different question for details

Community
  • 1
  • 1
barrowc
  • 10,444
  • 1
  • 40
  • 53
1

There is little I can think of immediately to add to the answer already given except, I often use the TypeName function e.g.

typename(myVariableOfInterest)

Typename

Returns a String that provides information about a variable.


For example, when working with a webpage I might write:

Dim a As Object: Set a = .document.getElementById("elementID")

And then in the immediate window do

TypeName(a)

Which generally tells me the datatype I am working with, for example, HTMLTable.

I take the returned string and then either, in no particular order:

  1. Google to find the listed methods/properties
  2. MSDN Developer search to find the listed methods/properties
  3. Use the object browser in Excel to search for the string and the listed methods/properties
QHarr
  • 83,427
  • 12
  • 54
  • 101