如何在VBA PowerQuery中添加动态变量 [英] How to add Dynamic Variable in VBA PowerQuery
本文介绍了如何在VBA PowerQuery中添加动态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
路径应首先由变量生成:
f = ThisWorkbook.Path & "Datadetails_" & Month([Date].Value) & "." & Day([Date].Value) & ".xlsx"
然后,应将变量放入PowerQuery:
ActiveWorkbook.Queries.Add Name:="PortalData", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Excel.Workbook(File.Contents(f), null, true)," & Chr(13) & "" & Chr(10) & " Table1_Table = Source{[Item=""Table1"",Kind=""Table""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Table1_Table,{...})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
File.Contents(F)搜索名为‘f
’的文件,而不是路径。File.Contents()
最初包含双引号中的路径,但向f添加双引号不起作用。
推荐答案
解决方案将替换:
File.Contents(""&f&"")
与
File.Contents(""" & f & """)
感谢@BigBen的帮助!
这篇关于如何在VBA PowerQuery中添加动态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文