+ Reply to Thread
Results 1 to 9 of 9

VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as shown in

  1. #1
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as shown in

    VBA Determine Object Type. ( From HTML DOM Object ( Node Type ) ). Put Type in String variable. ( Like that type shown in Watch and Immediate Windows.


    Hi
    I am using the Watch and Immediate Windows to good effect to monitor some parts of a code.

    This is OK, but in addition I would like to be able to store in a String variable some things I am seeing in these Windows. ( Ultimately I want to print out the string to a sort of “Debug Worksheet” or “Résumé Worksheet” )

    In particular, currently I have a Variable of Type Object. This changes its type, that is to say is Set to a different variable at different parts of a code. It is not always obvious ( to me ) what this Object type might be at any point. (_...... It is set to different nodes in a Document Object Model made from a .HTML files I made or “Got” from the URL of a website, _........- this Thread is a bit related to this one
    http://www.excelforum.com/excel-prog...te-change.html
    _....
    ..)

    )
    _.....

    So anyway. I see these for example during a code run
    objHTMLTableCell.JPG
    objHTMLTableCell.JPG
    objDispHTMLDOMTextNode.JPG
    objDispHTMLDOMTextNode.JPG



    I want in a string variable something to give me an indication of the Object Type, of this form or similar
    “HTMLTableCell”
    Or
    “DispHTMLDOMTextNode”

    Similarly I see in the same place in the Immediate window at other parts of the code a different Object type and correspondingly I am looking for getting a string of this form

    “HTMLTable”
    “HTMLTableSection”
    “HTMLTableRow”
    “DispHTMLDOMTextNode”


    I tried
    Debug.Print Elem
    This always returns [object] for the above example
    [object]
    [object]
    [object]
    [object]
    [object]
    [object]


    I tried looking at Elem.NodeType
    This gives me for the above example_....
    Element
    Text
    Element
    Element
    Element
    Element
    Text

    _...... this is only a bit better.

    _.............

    So does anyone know how I can get info into a string, that will look like that Object type description I see in the Immediate and Watch Windows. I guess that info must be somewhere – or else VBA could not put it in those windows... )

    Thanks
    Alan
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as show

    If you used early binding, you can see if Debug.Print Elem.Type produces what you want. That is if Type is a member of the object Elem.

  3. #3
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as show

    Hi Kennith
    Thanks very much for the reply.
    I have Early Binding in my main code, but I get no intellisense offerings for Elem where I am using it. -
    Elem I have declared at the signature line of a Called Sub routine
    Please Login or Register  to view this content.
    This routine gets “fed” in Elem HTML Objects . ( or nodes thereof ) in the first argument. Inside the called subroutine, by setting a watch or looking in the immediate window at a Debug.Print of Elem, I get the results indicated in post 1
    _...
    BTW. I made an error In post #1,I do not actually get using Elem.NodeType this_....
    Element
    Text
    Element
    Element
    Element
    Element
    Text
    _....
    I actually get_.......
    1
    3
    1
    1
    1
    1
    3
    _...... But I have a look Up Table which I found by googling which list the Node Types and the numbers given by .NodeType, and I do a VLookUp on that to get the results
    Element
    Text
    Element
    Element
    Element
    Element
    Text

    I tried your suggestion of
    Elem.Type
    Either using
    Debug.Print Elem.Type
    Or
    Dim v As Variant: Let v = Elem.Type
    But I get a the 438 Error of Object not supporting the Method or Property, so I guess that is telling us that Type is not a member of the object Elem. ( I guess I should be able to see that from the Object Browser, but somehow I can never seem to get the hang of that thing )
    At the same point in the code
    Elem.NodeType
    Or
    DeBug.Print Elem
    “works”, giving the results indicated.


    Thanks anyway for the suggestion

    I am hoping there is a way to get in a string what one sees in the Watch Window as I showed. That info must be held somewhere. I would have thought that this question has been asked before, but I have no luck in searching yet

    Thanks again for the reply

    Alan
    Last edited by Doc.AElstein; 07-27-2016 at 04:00 PM.

  4. #4
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as show

    Bump
    Hi
    I was hoping this question might have been asked before -- Just to summarise: I would like to get the Type displayed in the Watch window ( or immediate Widow ) into a string variable. ( I do not mean the basic variable type but what is in it.
    So referring to the screen shots in Post #1, I see
    Object/HTMLTableCell
    and I would like to get “HTMLTableCell” or similar into a string variable.

    Thanks, Alan.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as show

    Have you tried TypeName?
    If posting code please use code tags, see here.

  6. #6
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as show

    Hi Norie
    Quote Originally Posted by Norie View Post
    Have you tried TypeName?
    Thanks for the reply.
    TypeName gives "error 438 , Property or method not supported"
    Thanks anyway
    Alan

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as show

    Alan

    TypeName is a function, not a property.

  8. #8
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as show

    Quote Originally Posted by Norie View Post
    Alan

    TypeName is a function, not a property.
    Thanks for that, I like to get these things clear - The Help and Error messages are often a bit lacking in precision ( Or I translate it wrong from German .. Lol... )
    Alan

    ( But still, this Function does not appear to be available )
    Last edited by Doc.AElstein; 07-28-2016 at 10:08 AM.

  9. #9
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: VBA Determine Object Type (From HTML DOM Object) Put Type in String variable (as show

    Ah , I missed the point....
    Quote Originally Posted by Norie View Post
    Alan
    TypeName is a function, not a property.
    Here we go:_....
    https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx
    _.....

    Syntax for the TypeName Function:
    ( assuming somewhere I have __....
    __...... Elem As Object
    __ Set Elem As ______ ‘ ( Or if you do not do this.....

    Dim strTypeNameobjElem As String
    Let strTypeNameobjElem = TypeName(Elem) ‘ ...... will return “Nothing if Elem is not yet Set )

    SOLVED
    Sorry I missed the point , Norie

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] return the name and type of a shape object
    By mortphil in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-10-2014, 03:39 AM
  2. Replies: 0
    Last Post: 06-19-2014, 02:09 PM
  3. Replies: 6
    Last Post: 11-27-2013, 10:28 PM
  4. IE.Navigate not working [IE is an object variable of type InternetExplorer]
    By arjun.majumdar in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-05-2013, 04:51 AM
  5. Complile Error - Missing object or type
    By papasmurfuo9 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-05-2013, 06:38 AM
  6. Replies: 2
    Last Post: 03-31-2009, 03:55 PM
  7. [SOLVED] On-the-fly determination of object type?
    By Ed in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2005, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1