用于将 MS Word 表导出到 Excel 工作表的宏
我有一个包含许多表格的word文档。有谁知道如何编写宏将此类表导出到不同的 Excel 工作表?
I have a word document with many tables. Does anyone know how to write a macro to export such tables to different Excel sheets?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
答案取自: http://www.mrexcel.com/forum/showthread.php ?t=36875
下面是一些代码,用于将 Word 中的表格读取到 Excel 的活动工作表中。如果 Word 包含多个表格,它会提示您输入 Word 文档以及表格编号。
应将该宏插入到 Excel(而不是 Word)中并放入标准宏模块中,而不是放入工作表或工作簿事件代码模块中。为此,请转到 VBA(键盘 Alt-TMV),插入宏模块 (Alt-IM),然后将代码粘贴到代码窗格中。像运行任何其他界面一样从 Excel 界面运行宏 (Alt-TMM)。
如果您的文档包含许多表格,例如您的 100 多页表格实际上是每个页面上的单独表格,则可以轻松修改此代码以读取所有表格。但现在我希望它都是一张连续的表,不需要任何修改。
保持卓越。
Damon
VBAexpert Excel 咨询
(我的另一种生活:http://damonostrander.com)
Answer taken from: http://www.mrexcel.com/forum/showthread.php?t=36875
Here is some code that reads a table from Word into the active worksheet of Excel. It prompts you for the word document as well as the table number if Word contains more than one table.
This macro should be inserted into Excel (not Word) and put into a standard macro module rather than into the worksheet or workbook event code modules. To do this, go to the VBA (keyboard Alt-TMV), insert a macro module (Alt-IM), and paste the code into the code pane. Run the macro from the Excel interface as you would any other (Alt-TMM).
If your document contains many tables, as would be the case if your 100+ page table is actually a separate table on each page, this code could easily be modified to read all the tables. But for now I am hoping it is all one continuous table and will not require any modification.
Keep Excelling.
Damon
VBAexpert Excel Consulting
(My other life: http://damonostrander.com )
我更改了这个,添加了循环遍历所有表的功能(从从所选的表中):
下一个技巧:研究如何从 Word 中提取表中的表...我真的想要吗?
TC
I changed this one with an addition to loop through all tables (starting from the chosen table):
Next trick: working out how to extract a table within a table from Word... and do I really want to?
TC
非常感谢 Damon 和 @Tim,
我修改了它来打开 docx 文件,在检查用户的转义后移动了工作表的清晰行。
这是最终的代码:
Thank you so much Damon and @Tim
I modified it to open docx files, moved a worksheet clear line after checking for escape by user.
Here is the final code:
这一段代码是循环遍历每个表并将其复制到 Excel 的代码。也许您可以创建一个工作表对象,该对象使用表编号作为计数器来动态更新您所引用的工作表。
This section of code is the one that loops through each table and copies it to excel. Perhaps you could create a worksheet object that dynamically updates the worksheet you are referring to using the table number as a counter.