Cargar XML en Excel a través de VBA
Tengo un poco de VBA que carga un archivo XML a través de VBA. Sin embargo, cuando se importa, todo está en una columna y no se divide en una tabla.
Cuando lo importo manualmente a través de la pestaña Datos, recibo la advertencia de que no hay ningún esquema, pero me pregunta si me gustaría que Excel creara uno basado en los datos de origen. Esto coloca todos los datos en una buena mesa.
Me gustaría que esto sucediera automáticamente dentro de mi código VBA actual:
VBA se parece a
Sub refresh()
'--------------------------------1. Profile IDs-----------------------------------'
'date variables
Dim start_period As String
start_period = Sheets("Automated").Cells(1, 6).Value
Dim end_period As String
end_period = Sheets("Automated").Cells(1, 7).Value
'report id variable names
Dim BusinessplanningReportID As String
'--------------------------------REST queries--------------------------------'
Dim Businessplanning As String
'REST query values
Businessplanning = "URL;http://api.trucast.net/2/saved_searches/00000/pivot/content_volume_trend/?apikey=0000000&start=" + start_period + "&end=" + end_period + "&format=xml"
'--------------------------------------------Data connections-----------------------------------'
'key metrics
With Worksheets("Sheet1").QueryTables.Add(Connection:=Businessplanning, Destination:=Worksheets("Sheet1").Range("A1"))
.RefreshStyle = xlOverwriteCells
.SaveData = True
End With
Actualmente los datos se presentan así, desestructurados. ¿Cómo puedo convertir esto automáticamente en una tabla?
<result>
<entry>
<published_date>20130201</published_date>
<post_count>18</post_count>
</entry>
Gracias,
::Solución final::
Sub XMLfromPPTExample2()
Dim XDoc As MSXML2.DOMDocument
Dim xresult As MSXML2.IXMLDOMNode
Dim xentry As MSXML2.IXMLDOMNode
Dim xChild As MSXML2.IXMLDOMNode
Dim start_period As String
start_period = Sheets("Automated").Cells(1, 6).Value
Dim end_period As String
end_period = Sheets("Automated").Cells(1, 7).Value
Dim wb As Workbook
Dim Col As Integer
Dim Row As Integer
Set XDoc = New MSXML2.DOMDocument
XDoc.async = False
XDoc.validateOnParse = False
XDoc.Load ("http://api.trucast.net/2/saved_searches/0000/pivot/content_volume_trend/?apikey=00000&start=" + start_period + "&end=" + end_period + "&format=xml")
LoadOption = xlXmlLoadImportToList
Set xresult = XDoc.DocumentElement
Set xentry = xresult.FirstChild
Col = 1
Row = 1
For Each xentry In xresult.ChildNodes
Row = 1
For Each xChild In xentry.ChildNodes
Worksheets("Sheet2").Cells(Col, Row).Value = xChild.Text
'MsgBox xChild.BaseName & " " & xChild.Text
Row = Row + 1
'Col = Col + 1
Next xChild
'Row = Row + 1
Col = Col + 1
Next xentry
End Sub