0

This is my first attempt to use MSXML2.DOMDocument within VBA, and I'm having a "huh?" moment right off the start. My document looks like this...

<Locations>
    <Location ID="23456">
        <Properties>
            <Property ID="12345">
etc.

I want to make a report with all the Location IDs, so I:

Set locs= XDoc.SelectNodes("//Location")
For Each loc In locs
     Debug.Print loc.Attributes(0).Text
Next

and I got 23456. Yay! But of course, those attributes might move around, so let's fix that...

     Debug.Print loc.getAttribute("ID").Text

That returns Object required. Looking in the debugger, I can see that loc has one attribute and it's name is ID. That seems right. I can also see that loc.getAttribute("ID") returns null. That seems wrong.

So what's going on here?

Community
  • 1
  • 1
Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98
  • Try this `Debug.Print loc.getAttribute("ID")`. It should fix the issue. – SIM Mar 31 '18 at 16:37
  • @SIM - that worked and I'll upvote if you make it an answer. But WHY does this work? is it "if it says get then this returns text" sort of thing? – Maury Markowitz Apr 03 '18 at 13:38

1 Answers1

0

I don't know VBA at all but my guess would be that the .attributes[] property returns an attribute object (XmlAttribute?), which would let you access its identifier and value, whereas the getAttribute() function is the getter for the text value of the attribute with that identifier.

Alain T.
  • 40,517
  • 4
  • 31
  • 51