vba 我可以将查询表(和连接?)复制到其他工作簿吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11672049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I copy query tables (and connections?) to other workbooks?
提问by Air_Cooled_Nut
I have a workbook (wkbk1) that has a sheet with eight different query tables (a.k.a. data tables) on it -- NOT PIVOT TABLES. They all point to the same external Excel workbook (wkbk2) for their data which is a single sheet with a group of named ranges.
我有一个工作簿 (wkbk1),其中有一张工作表,上面有八个不同的查询表(又名数据表)——不是数据透视表。它们都指向相同的外部 Excel 工作簿 (wkbk2) 以获取其数据,该工作簿是具有一组命名范围的单个工作表。
The data for each table in wkbk1 comes from a named range in wkbk2. How can I copy the sheet of eight different tables (from wkbk1) to other workbooks (wkbk3, wkbk4, etc)?
wkbk1 中每个表的数据来自 wkbk2 中的命名范围。如何将八个不同表(从 wkbk1)的工作表复制到其他工作簿(wkbk3、wkbk4 等)?
Is it even possible for the query table and its data connection to transfer with the sheet? So far I can't do it manually (no coding). If coding is required I'm fine with that, just need help with it. I have intermediate VBA coding experience.
查询表及其数据连接是否可以与工作表一起传输?到目前为止,我无法手动完成(无编码)。如果需要编码,我很好,只需要帮助。我有中级 VBA 编码经验。
I'm using Excel 2007/2010.
我正在使用 Excel 2007/2010。
回答by Dick Kusleika
In Excel 2010, I right click on the sheet tab and choose Move or Copy. Select the destination workbook and check "Create a Copy". The new sheet has the QueryTable on it and refreshes as expected.
在 Excel 2010 中,我右键单击工作表选项卡并选择“移动”或“复制”。选择目标工作簿并选中“创建副本”。新工作表上有 QueryTable 并按预期刷新。
So I think copying the sheet will copy the QueryTable and all its properties.
所以我认为复制工作表将复制 QueryTable 及其所有属性。
My QueryTable used MSQuery and pointed to another Excel workbook.
我的 QueryTable 使用 MSQuery 并指向另一个 Excel 工作簿。