请参: '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-7-2 10:05:10
'仅测试于System: Windows NT Excel: 10.0 Language: 2052
'* -----------------------------
Option Explicit
'此程序代码运行于EXCEL工作薄(数据源)中
Sub MailMergeToWordPrinter()
'运行此程序前请检查VBE/工具/引用中,确认对于Microsoft Word 10.0 Object Library
'请不要打开WORD程序
Dim MyWordApp As New Word.Application, MyMailMergeDoc As Word.Document
With MyWordApp
'打开指定的WORD邮件合并主文档,注意确保在同一文件夹中,如果不是,请写明全路径
Set MyMailMergeDoc = .Documents.Open(ThisWorkbook.Path & "\来生缘.Doc")
'主文档的邮件合并对象
With MyMailMergeDoc.MailMerge
'邮件合并操作的结果传送到打印
.Destination = wdSendToPrinter
'邮件合并域为空时,就删除该空行
.SuppressBlankLines = True
'合并全部数据源数据
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
'合并域
.Execute Pause:=False
End With
'关闭主文档
MyMailMergeDoc.Close False
'退出WORD程序
.Quit
'释放对象变量
Set MyWordApp = Nothing
End With
End Sub
'----------------------
b4gbItel.rar
(13.71 KB, 下载次数: 62)
[此贴子已经被作者于2005-7-2 10:12:24编辑过] |