【发布时间】:2020-09-03 13:28:48
【问题描述】:
我正在尝试通过电源查询提取数据,但我收到“无效的过程调用或参数”错误
我尝试过使用数组和 lin 输入的其他选项,但由于它们花费了太多时间,我不得不转向另一个选项。
错误在行:ActiveWorkbook.Queries.Add Name:=QueryName, Formula:=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
源公式查询是从 power 查询编辑器复制粘贴的,我刚刚使用了额外的转义字符。
【问题讨论】:
标签: excel vba import text-files powerquery