Laden Sie XML über VBA in Excel

Ich habe ein bisschen VBA, das eine XML-Datei über VBA lädt. Beim Importieren befindet sich jedoch alles in einer Spalte und wird nicht in eine Tabelle aufgeteilt.

Wenn ich dies manuell über die Registerkarte "Daten" importiere, wird die Warnung angezeigt, dass kein Schema vorhanden ist. Ich werde jedoch gefragt, ob Excel ein Schema basierend auf den Quelldaten erstellen soll. Dies platziert dann alle Daten in einer schönen Tabelle.

Ich möchte, dass dies in meinem aktuellen VBA-Code automatisch geschieht:

VBA sieht aus wie

      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

Momentan präsentieren sich die Daten dann so, unstrukturiert. Wie kann ich das automatisch in einen Tisch verwandeln?

<result>
<entry>
<published_date>20130201</published_date>
<post_count>18</post_count>
</entry>

Vielen Dank,

::Endgültige Lösung::

 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

Antworten auf die Frage(2)

Ihre Antwort auf die Frage