Sub histiry()
Dim xq
For Each xq In ThisWorkbook.Queries
xq.Delete
Next xq
Workbooks("VBA Lessons.xlsm").Worksheets("HistoryPrice").Cells.ClearContents
Dim ticker As String
ticker = Workbooks("VBA Lessons.xlsm").Worksheets("HistoryPrice").Range("U2")
ActiveWorkbook.Queries.Add Name:= _
"AAPL?period1=1686209419&period2=1717831820&interval=1d&events=history&includeAdj" _
, Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Источник = Csv.Document(Web.Contents("";, Columns=7, Encoding=65001, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & " #""Повышенные заголовки"" = Table.PromoteHeaders(Источник, [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & " " & _
" #""Измененный тип"" = Table.TransformColumnTypes(#""Повышенные заголовки"",{{""Date"", type date}, {""Open"", type text}, {""High"", type text}, {""Low"", type text}, {""Close"", type text}, {""Adj Close"", type text}, {""Volume"", Int64.Type}})," & Chr(13) & "" & Chr(10) & " #""Замененное значение"" = Table.ReplaceValue(#""Измененный тип"",""."","","",Replacer.ReplaceText,{""Open""})," & Chr(13) & "" & Chr(10) & "" & _
" #""Замененное значение1"" = Table.ReplaceValue(#""Замененное значение"",""."","","",Replacer.ReplaceText,{""High""})," & Chr(13) & "" & Chr(10) & " #""Замененное значение2"" = Table.ReplaceValue(#""Замененное значение1"",""."","","",Replacer.ReplaceText,{""Low""})," & Chr(13) & "" & Chr(10) & " #""Замененное значение3"" = Table.ReplaceValue(#""Замененное значение2"",""."","","",Replacer.ReplaceText,{""Close""})" & _
"," & Chr(13) & "" & Chr(10) & " #""Замененное значение4"" = Table.ReplaceValue(#""Замененное значение3"",""."","","",Replacer.ReplaceText,{""Adj Close""})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Замененное значение4"""
'ActiveWorkbook.Worksheets.Add
With ActiveWorkbook.Worksheets("HistoryPrice").ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""AAPL?period1=1686209419&period2=1717831820&interval=1d&events" _
, "=history&includeAdj"";Extended Properties="""""), Destination:=Range("$A$1" _
)).QueryTable
.CommandType = xlCmdSql
.CommandText = Array( _
"SELECT * FROM [AAPL?period1=1686209419&period2=1717831820&interval=1d&events=history&includeAdj]" _
)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = _
"AAPL_period1_1686209419_period2_1717831820_interval_1d_even ts_history_includeAdj"
.Refresh BackgroundQuery:=False
End With
Range("H6").Select
Application.CommandBars("Queries and Connections").Visible = False
Range("K2").Select
End Sub
Ошибка: 1004: Application-defined or object-defined error.
В строке: .Refresh BackgroundQuery:=False
Dim xq
For Each xq In ThisWorkbook.Queries
xq.Delete
Next xq
Workbooks("VBA Lessons.xlsm").Worksheets("HistoryPrice").Cells.ClearContents
Dim ticker As String
ticker = Workbooks("VBA Lessons.xlsm").Worksheets("HistoryPrice").Range("U2")
ActiveWorkbook.Queries.Add Name:= _
"AAPL?period1=1686209419&period2=1717831820&interval=1d&events=history&includeAdj" _
, Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Источник = Csv.Document(Web.Contents("";, Columns=7, Encoding=65001, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & " #""Повышенные заголовки"" = Table.PromoteHeaders(Источник, [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & " " & _
" #""Измененный тип"" = Table.TransformColumnTypes(#""Повышенные заголовки"",{{""Date"", type date}, {""Open"", type text}, {""High"", type text}, {""Low"", type text}, {""Close"", type text}, {""Adj Close"", type text}, {""Volume"", Int64.Type}})," & Chr(13) & "" & Chr(10) & " #""Замененное значение"" = Table.ReplaceValue(#""Измененный тип"",""."","","",Replacer.ReplaceText,{""Open""})," & Chr(13) & "" & Chr(10) & "" & _
" #""Замененное значение1"" = Table.ReplaceValue(#""Замененное значение"",""."","","",Replacer.ReplaceText,{""High""})," & Chr(13) & "" & Chr(10) & " #""Замененное значение2"" = Table.ReplaceValue(#""Замененное значение1"",""."","","",Replacer.ReplaceText,{""Low""})," & Chr(13) & "" & Chr(10) & " #""Замененное значение3"" = Table.ReplaceValue(#""Замененное значение2"",""."","","",Replacer.ReplaceText,{""Close""})" & _
"," & Chr(13) & "" & Chr(10) & " #""Замененное значение4"" = Table.ReplaceValue(#""Замененное значение3"",""."","","",Replacer.ReplaceText,{""Adj Close""})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Замененное значение4"""
'ActiveWorkbook.Worksheets.Add
With ActiveWorkbook.Worksheets("HistoryPrice").ListObjects.Add(SourceType:=0, Source:=Array( _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""AAPL?period1=1686209419&period2=1717831820&interval=1d&events" _
, "=history&includeAdj"";Extended Properties="""""), Destination:=Range("$A$1" _
)).QueryTable
.CommandType = xlCmdSql
.CommandText = Array( _
"SELECT * FROM [AAPL?period1=1686209419&period2=1717831820&interval=1d&events=history&includeAdj]" _
)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = _
"AAPL_period1_1686209419_period2_1717831820_interval_1d_even
.Refresh BackgroundQuery:=False
End With
Range("H6").Select
Application.CommandBars("Queries and Connections").Visible = False
Range("K2").Select
End Sub
Ошибка: 1004: Application-defined or object-defined error.
В строке: .Refresh BackgroundQuery:=False