小编Jon*_*Boy的帖子

如何在VBA中自动执行电源查询?

我在表1中有数据.通常我会进行电源查询并进行转换,然后关闭,并加载到现有工作表2.

我想使用VBA自动执行此操作,我可以自动运行电源查询并将转换填充到第2页.

宏录制器似乎不允许我记录步骤.在网上没有太多关于这样做的事情.

尝试一些更简单的代码:

Sub LoadToWorksheetOnly()

'Sub LoadToWorksheetOnly(query As WorkbookQuery, currentSheet As Worksheet)
    ' The usual VBA code to create ListObject with a Query Table
    ' The interface is not new, but looks how simple is the conneciton string of Power Query:
    ' "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & query.Name

    query = Sheets("Sheet6").Range("A1").value 'here is where my query from power query is. I put the text from power query avanced editor in another sheet cell.
    currentSheet = ActiveSheet.Name
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data …
Run Code Online (Sandbox Code Playgroud)

excel vba powerquery

13
推荐指数
2
解决办法
2万
查看次数

标签 统计

excel ×1

powerquery ×1

vba ×1