Я пытаюсь выяснить, как выбрать разные источники запроса вручную через VBA. Я получаю сообщение об ошибке, поскольку источник не найден.
ОШИБКА ВРЕМЕНИ РАБОТЫ
ОПЦИЯ ОТЛАДКИ ОШИБКА ЗАПРОСА ПОСЛЕ РАБОТЫ VBA
Sub Import()
'
' Import Macro
'
Dim fname As String
fname = Application.GetOpenFilename("Text Files (*.txt), *.txt")
ActiveWorkbook.Queries.Add Name:="Data", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Csv.Document(""" & fname & """),[Delimiter="" "", Columns=3, Encoding=1252, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Source,{{""Column1"", type text}, {""Column2"", type text}, {""Column3"", type text}})," & Chr(13) & "" & Chr(10) & " #""Removed Columns"" = Table.Rem" & _
"oveColumns(#""Changed Type"",{""Column2""})," & Chr(13) & "" & Chr(10) & " #""Renamed Columns"" = Table.RenameColumns(#""Removed Columns"",{{""Column1"", ""HANDLE""}, {""Column3"", ""CIRCUIT""}})," & Chr(13) & "" & Chr(10) & " #""Removed Top Rows"" = Table.Skip(#""Renamed Columns"",2)" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Removed Top Rows"""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Data"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Data]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Data"
.REFRESH BackgroundQuery:=False
End With
'
End Sub