首页 > 解决方案 > How to create a macro in word to import multiple tables from excel?

问题描述

Frequently in my job I need to generate reports with lots of tables of inputs and results. Especially for the result tables, one change in analysis may require editing a dozen spreadsheets. I'd like to create a macro in word that pulls in data from a spreadsheet, with each table on it's own tab, so that if I update any of those tables in excel the word document tables will also update. Given the number of tables/data points, I don't want to have to tell the macro to pull each single data point. The aim would be to reduce time and errors from manual entry.

I'm thinking this would involve the following steps, but not sure how to go about them: 1) Define the name/size for each table in word with matching name/size in excel 2) Tell the macro to pull the data into a table format

I'm not sure if this is possible as so far I've only seen how to insert a caption or a text box, not insert or update entire tables. Any help would be greatly appreciated!

标签: vbams-word

解决方案


根据您所做的事情,您甚至可能不需要任何 VBA 代码。

如果您从 Excel 复制一个区域并使用“粘贴链接”选项使用选择性粘贴将其粘贴到 Word 中,则保存工作簿时,Excel 区域中的任何后续更改都将自动反映在文档中。而且,如果您在复制/粘贴之前在 Excel 中命名范围,Word 内容将扩展/收缩以反映 Excel 中命名范围范围的变化。支持多种粘贴格式。

或者,您可以在 Word 中使用 DATABASE 字段。


推荐阅读