0

I am having problems getting the value of "Data Import" from the source_lvl2 child node. In Excel, I get a run-time error of 91, "Object variable or With block variable not set"

I can't see what I'm doing wrong - any advice?

VBA

Sub TestXML()
Dim XDoc As Object

Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.async = False: XDoc.validateOnParse = False
XDoc.Load ("C:\171215-000438_1513346972.xml")

Set lists = XDoc.SelectNodes("/archive/primary_rnw_contact/source/source_lvl2")
Debug.Print lists(0).Attributes(0).Text
Set XDoc = Nothing
End Sub

XML

enter image description here

EXTRA CODE

<?xml version="1.1" encoding="UTF-8"?>
<archive product="RightNow" version="4.0" build="17.8.0.1.0.248" label="Archived Incident">
pee2pee
  • 3,619
  • 7
  • 52
  • 133

1 Answers1

0

You could try the following (not tested):

Dim xmap As XmlMap
Dim k as Long
Dim oMyNewColumn As ListColumn
oMyList As ListObject

' Delete all previous XML maps
k = ThisWorkbook.XmlMaps.Count 'Detect all XML maps

For i = 1 To k
        ThisWorkbook.XmlMaps(i).Delete
Next i

...


Set xmap = ThisWorkbook.XmlMaps.Add("some_file.xml")

...

Set oMyNewColumn = oMyList.ListColumns.Add
    oMyList.ListColumns(3).XPath.SetValue xmap, "/archive/primary_rnw_contact/source/source_lvl2"