23.06.2025, 20:35
Hallo zusammen,
ich versuche gerade ein Makro zu erstellen, um Tabellen aus dem Web herunter zu laden. Mit Daten aus dem Web abrufen kein Problem, soweit es nur eine Tabelle betrifft. Aber daraus in einer Schleife mehrere Seiten abzurufen klappt nicht.
Fakten:
Url zum Abruf: https://www.xxxxxx.net/de/yyyy_ danach folgen überwiegend fortlaufende Nummern, die in einer Tabelle vorliegen und aus dieser Zeilenweise ausgelesen werden sollen.
Aufgezeichnetes Makro ergibt für eine einzelne Seite bspw. diesen Code:
Versuche ich dann, diesen Code in eine Schleife zu legen, dann stürzt der Code in der drittletzten Zeile:
ab.
Wie kann ich mehrere Tabellen nacheinander abrufen und untereinander stapeln?
ich versuche gerade ein Makro zu erstellen, um Tabellen aus dem Web herunter zu laden. Mit Daten aus dem Web abrufen kein Problem, soweit es nur eine Tabelle betrifft. Aber daraus in einer Schleife mehrere Seiten abzurufen klappt nicht.
Fakten:
Url zum Abruf: https://www.xxxxxx.net/de/yyyy_ danach folgen überwiegend fortlaufende Nummern, die in einer Tabelle vorliegen und aus dieser Zeilenweise ausgelesen werden sollen.
Aufgezeichnetes Makro ergibt für eine einzelne Seite bspw. diesen Code:
Code:
ActiveWorkbook.Queries.Add Name:="Tabelle 1", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Quelle = Web.BrowserContents(""https://www.xxxxxx.net/de/yyyy_"")," & Chr(13) & "" & Chr(10) & " #""Aus HTML-Code extrahierte Tabelle"" = Html.Table(Quelle, {{""Column1"", ""TABLE[id='abcde'] > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(5), TABLE[id='abcde'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(3), TABLE[i" & _
"d='abcde'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(5)""}, {""Column2"", ""TABLE[id='abcde'] > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(5) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(4), TABLE[id='abcde'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(3) " & _
"+ TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(2), TABLE[id='abcde'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(5) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(4)""}, {""Column3"", ""TABLE[id='abcde'] > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(5) + TH:not([colspan]):not" & _
"([rowspan]):nth-child(2):nth-last-child(4) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(3), TABLE[id='abcde'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(3) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(2) + TD[colspan=""""3""""]:not([rowspan]):nth-child(3):nth-last-child(1), TABLE[id='abcde'] > * " & _
"> TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(5) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(4) + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(3)""}, {""Column4"", ""TABLE[id='abcde'] > * > TR > TH:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(5) + TH:not([colspan]):not([rowspan]):nth-child(2):n" & _
"th-last-child(4) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(3) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(2), TABLE[id='abcde'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(3) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(2) + TD[colspan=""""3""""]:not([rowspan]):nth-child(3):nth-" & _
"last-child(1), TABLE[id='abcde'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(5) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(4) + TD:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(3) + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(2)""}, {""Column5"", ""TABLE[id='abcde'] > * > TR > TH:not(" & _
"[colspan]):not([rowspan]):nth-child(1):nth-last-child(5) + TH:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(4) + TH:not([colspan]):not([rowspan]):nth-child(3):nth-last-child(3) + TH:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(2) + TH:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(1), TABLE[id='abcde'] > * > TR > TD:not([colspa" & _
"n]):not([rowspan]):nth-child(1):nth-last-child(3) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(2) + TD[colspan=""""3""""]:not([rowspan]):nth-child(3):nth-last-child(1), TABLE[id='abcde'] > * > TR > TD:not([colspan]):not([rowspan]):nth-child(1):nth-last-child(5) + TD:not([colspan]):not([rowspan]):nth-child(2):nth-last-child(4) + TD:not([colspan])" & _
":not([rowspan]):nth-child(3):nth-last-child(3) + TD:not([colspan]):not([rowspan]):nth-child(4):nth-last-child(2) + TD:not([colspan]):not([rowspan]):nth-child(5):nth-last-child(1)""}}, [RowSelector=""TABLE[id='abcde'] > * > TR""])," & Chr(13) & "" & Chr(10) & " #""Geänderter Typ"" = Table.TransformColumnTypes(#""Aus HTML-Code extrahierte Tabelle"",{{""Column1"", type text}, {""Column2"", " & _
"type text}, {""Column3"", type text}, {""Column4"", type text}, {""Column5"", type text}})," & Chr(13) & "" & Chr(10) & " #""Entfernte Spalten"" = Table.RemoveColumns(#""Geänderter Typ"",{""Column1""})," & Chr(13) & "" & Chr(10) & " #""Entfernte oberste Zeilen"" = Table.Skip(#""Entfernte Spalten"",2)," & Chr(13) & "" & Chr(10) & " #""Spalte nach Trennzeichen teilen"" = Table.SplitColumn(#""Entfernte oberste Zeilen"", ""Column4"", Splitter." & _
"SplitTextByDelimiter(""#(00A0)"", QuoteStyle.Csv), {""Column4.1"", ""Column4.2""})," & Chr(13) & "" & Chr(10) & " #""Geänderter Typ1"" = Table.TransformColumnTypes(#""Spalte nach Trennzeichen teilen"",{{""Column4.1"", type text}, {""Column4.2"", type text}})," & Chr(13) & "" & Chr(10) & " #""Entfernte Spalten1"" = Table.RemoveColumns(#""Geänderter Typ1"",{""Column4.2""})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Entfernte Spalten1"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Tabelle 1"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Tabelle 1]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Tabelle_1"
.Refresh BackgroundQuery:=False
End With
Code:
.ListObject.DisplayName = "Tabelle_1"
Wie kann ich mehrere Tabellen nacheinander abrufen und untereinander stapeln?
Gruß
Edgar
Meine Antworten sind freiwillig und ohne Gewähr!
Über Rückmeldungen würde ich mich freuen.
Edgar
Meine Antworten sind freiwillig und ohne Gewähr!
Über Rückmeldungen würde ich mich freuen.