vba - 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!
解决方案
根据您所做的事情,您甚至可能不需要任何 VBA 代码。
如果您从 Excel 复制一个区域并使用“粘贴链接”选项使用选择性粘贴将其粘贴到 Word 中,则保存工作簿时,Excel 区域中的任何后续更改都将自动反映在文档中。而且,如果您在复制/粘贴之前在 Excel 中命名范围,Word 内容将扩展/收缩以反映 Excel 中命名范围范围的变化。支持多种粘贴格式。
或者,您可以在 Word 中使用 DATABASE 字段。
推荐阅读
- apache-kafka - Kafka不在分区之间分配数据
- python - POST 响应标头中不存在位置字段
- javascript - VueJS 砌体布局
- javascript - 在本地服务器上与贝宝集成
- asp.net - 无法在 ASP.NET MVC 中设置当前日期
- html - 将按钮与文本保持在同一行
- python-3.x - 如何避免 UnboundLocalError?
- php - 如何在 C++ 服务器中解码 curl url 编码的字符串
- java - 在 Spring Data jpa 中使用调度程序进行休眠缓存
- python - Selenium:使用用户名/密码通过代理连接 - 如何?