У меня есть смесь VBA и макроса для извлечения таблицы веб-сайта, но она не обновляет имя таблицы при запуске и должна быть вручную изменена перед запуском. Любая помощь будет принята с благодарностью.
Sub NZXMarket()
'
' NZXMarket Macro
' Daily list of NZX market
'
'
ActiveWorkbook.Queries.Add Name:="Table 0 (4)", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://www.nzx.com/markets/NZSX""))," & Chr(13) & "" & Chr(10) & " Data0 = Source{0}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data0,{{""Code"", type text}, {""Company"", type text}, {""Price"", Currency.Type}, {""Change"", type text}, {""Volume"", type number}, {""Value"", Currency.Type}, {""Capitalisation"", Currency.Type}, {""Pe" & _
"rcentage Change"", type number}, {""Type"", type text}, {""Green Bond"", type logical}, {""Trade Count"", Int64.Type}, {""Currency Code"", type text}, {""Market Capitalisation"", Currency.Type}})," & Chr(13) & "" & Chr(10) & " #""Removed Columns"" = Table.RemoveColumns(#""Changed Type"",{""Green Bond"", ""Currency Code""})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Removed Columns"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Table 0 (2)"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Table 0 (2)]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Table_0__4"
.Refresh BackgroundQuery:=False
End With
ActiveSheet.Name = Format(Date, "DD-MM-YY")
MsgBox "Download Complete"
End Sub