I use this function to get recordsets from Range-Objects without setting up ADO-connections.
Function GetRecordset(rng As Range) As Object
Dim xlXML As Object
Dim rst As Object
Set rst = CreateObject("ADODB.Recordset")
Set xlXML = CreateObject("MSXML2.DOMDocument")
xlXML.LoadXML rng.Value(xlRangeValueMSPersistXML)
rst.Open xlXML
Set GetRecordset = rst
End Function
I typically use one header row. I get the expected results if the data starts in Row(1).
However, if there are 1+ Rows above the data, excel assumes i have two header-rows and concatenates them with a blank.
Therefore, my recordset uses Fieldnames like ![Underneath's your header, mate MyField] instead of ![MyField].
More technically speaking, the problem is that rng.Value(xlRangeValueMSPersistXML) returns the concatenated two rows as header and I'm unable to set that to one row.
Interested to hear your thoughts!
EDIT: a workaround might be to replace leading blanks with something like
xlXML.LoadXML Replace(rng.Value(xlRangeValueMSPersistXML), "rs:name="" ", "rs:name=""")
or an iterative
Replace XML, "rs:name=""Cell1 Cell", "rs:name=""Cell2")
for each datafield
Rangeyou pass the function - i.e. define your range starting inRow(2)...Range.Valuewill extend it's range to get a value forAttributeType rs:name="<<Header>>"to up to twoRowsupwards.