vba 使用邮件合并从 Excel 文件生成 Word 文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3182425/
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
Generate word documents from excel file using mail merge
提问by Justin Leveck
I am trying to generate word documents using the mail merge feature in Microsoft Word. To be as clear as possible my dream would be to:
我正在尝试使用 Microsoft Word 中的邮件合并功能生成 Word 文档。为了尽可能清楚,我的梦想是:
(1) Place all values for all documents to be created in one excel document (2) Use Word to create a template by selecting the above excel file as the data sheet (3) Run a macro that would use the values from the excel sheet and perhaps the built in mail merge feature of Word to generate 1 file for each line in the excel sheet using one of the cells as the name of the file to be saved.
(1) 将要创建的所有文档的所有值放在一个 Excel 文档中 (2) 使用 Word 创建模板,选择上述 excel 文件作为数据表 (3) 运行一个宏,该宏将使用 Excel 表中的值也许 Word 的内置邮件合并功能可以使用其中一个单元格作为要保存的文件的名称为 Excel 工作表中的每一行生成 1 个文件。
The end result would be the ability to create x number of Word documents using a template that pulls all the values from an excel sheet including the file name of the generated document.
最终结果是能够使用模板创建 x 个 Word 文档,该模板从 Excel 工作表中提取所有值,包括生成的文档的文件名。
Please help.
请帮忙。
Thanks in advance.
提前致谢。
采纳答案by ArBR
You can do it by using Word and Excel Automation, using languages such as Visual Basic 6 (through COM
), VB .Net (through interop
) or C# (through interop
), for example for getting data from a database. In your case because you simply want to create a documente based on excel data the simplest manner is to use the MS Word Mail's Merge Wizard.
您可以使用Word 和 Excel 自动化,使用诸如 Visual Basic 6(至COM
)、VB .Net(至interop
)或 C#(至interop
)之类的语言,例如从数据库获取数据。在您的情况下,因为您只想基于 excel 数据创建文档,最简单的方法是使用 MS Word Mail 的合并向导。
Take a look at: http://office.microsoft.com/en-us/excel-help/print-labels-by-using-excel-data-in-a-word-mail-merge-HP005203760.aspx
看看:http: //office.microsoft.com/en-us/excel-help/print-labels-by-using-excel-data-in-a-word-mail-merge-HP005203760.aspx