vba 如何在 Word 模板中使用 Excel 中的数据创建报告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19149500/
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
How To create a report using data from Excel in Word Template
提问by The JAVA Noob
Summary:
I have to fill in a report using data from Excel in Word Template.
Problem:
I am trying to write a macro which will search some variables in pre-defined template (doc) and replace these variables with data from excel. The variables are nothing but some text like <-Date->, <-Author-> (self-created).
There are also some Tables and Sections that needs to be duplicated from the Word Template depending on the Excel Data.
For Example
I'll need to make 3 more Sections for Dates. Because
Word
1.<-Date->
摘要:我必须使用 Word 模板中的 Excel 数据填写报告。问题:我正在尝试编写一个宏,它将搜索预定义模板 (doc) 中的一些变量,并将这些变量替换为来自 excel 的数据。变量只不过是一些文本,如 <-Date->、<-Author->(自创)。根据 Excel 数据,还有一些表格和部分需要从 Word 模板中复制。例如,
我需要为日期制作另外 3 个部分。因为 Word
1.<-日期->
Excel 03-10-2013 04-10-2013 05-10-2013
Excel 03-10-2013 04-10-2013 05-10-2013
After Macro 1. 03-10-2013
宏 1. 03-10-2013 之后
04-10-2013
05-10-2013
04-10-2013
05-10-2013
Thanks in advance.
提前致谢。
回答by LaloInDublin
You do not need macros at all for this, MailMerge works extremely well to import and auto generate word documents from Excel for this very reason - and it's built right into Word:
为此,您根本不需要宏,出于这个原因,MailMerge 非常适合从 Excel 导入和自动生成 Word 文档 - 它已内置于 Word 中:
http://office.microsoft.com/en-us/word-help/mail-merge-using-an-excel-spreadsheet-HA102809678.aspx
http://office.microsoft.com/en-us/word-help/mail-merge-using-an-excel-spreadsheet-HA102809678.aspx