在电源查询Excel VBA中获取无效的过程调用或参数错误

问题描述 投票:0回答:1

我正在尝试通过超级查询获取数据,但收到“无效的过程调用或参数”错误

我已经尝试过使用数组和lin输入的其他选项,但是由于它们花费了太多时间,因此我不得不转向另一个选项。

错误所在行:ActiveWorkbook.Queries.Add名称:= QueryName,公式:= SourceFormula)

下面是代码:

Sub Import_AACR()

Dim QueryName, SourceFormula, ConnStr As String

QueryName = "AACR_Pull"

SourceFormula = "let Source = Csv.Document(File.Contents(""C:\ENDO AACR\AACR_20200123_2020Q1_V6.0.txt""),[Delimiter=""|"", Columns=27, Encoding=1252, QuoteStyle=QuoteStyle.None])," & _
    "#""Promoted Headers"" = Table.PromoteHeaders(Source, [PromoteAllScalars=true])," & _
    "#""Changed Type"" = Table.TransformColumnTypes(#""Promoted Headers"",{{""REQUEST#"", Int64.Type}, {""REQUEST_SUBMIT_DT"", type text}, {""REQUEST_SUBMIT_TYPE"", type text}, {""SALES_TEAM"", type text}, {""DM_NAME"", type text}, {""STATUS"", type text}})in #""Changed Type"""


ActiveWorkbook.Queries.Add Name:=QueryName, Formula:=SourceFormula


Connstr = "OLEDB;" & _
"Provider = Microsoft.Mashup.OleDb.1;" & _
"Data Source = $Workbook$;" & _
"Location=""AACR_Pull"";" & _
"Extended Properties="""""


With ActiveSheets.ListObjects.Add(SourceType = xlSrExternal, _
LinkSource:=True, _
xlListObjectHasHeaders:=xlYes, _
Source:=Connstr, _
TableStyleName:="TableStyleMedium8", _
Destinatio:=Range("A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [AACR_Pull]")
.Refresh BackgroundQuery = False
End With

End Sub

源公式查询是从超级查询编辑器复制粘贴的,而我刚刚使用了其他转义字符。

excel vba import text-files powerquery
1个回答
0
投票
经过一天的研究,我发现了另一个使用定界符导入相同文本文件的解决方法。
© www.soinside.com 2019 - 2024. All rights reserved.