使用ms访问邮件合并后word文档打开最小化

时间:2014-01-09 11:24:32

标签: ms-access-2007

我有以下代码使用VBA执行邮件合并,在执行邮件合并后word文档打开最小化,有没有办法让文档正常打开(最大化)?

Dim DocName As String
Echo -1, "Merge in progress..."



Dim templateName As String, tempRoot As String

tempRoot = "c:\temp\mailmerge"

templateName = tempRoot & "CertificateRSZDutch.dotx"

Dim objDoc As Word.Document

Dim objWord As New Word.Application

Set objDoc = objWord.Documents.Open(templateName)

objWord.Visible = True


DoCmd.TransferText acExportDelim, , "Mailmerge_CertificateRSZDutch", "Q:\jas\hr\mailmerge\LES\CertificateRSZDutch.txt", True

objDoc.MailMerge.OpenDataSource Name:= _

tempRoot & "CertificateRSZDutch.txt", ConfirmConversions:=False, ReadOnly _

:=False, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:= _

"", PasswordTemplate:="", WritePasswordDocument:="", _

WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _

Connection:="", SQLStatement:="", SQLStatement1:="", SubType:= _

wdMergeSubTypeOther


objDoc.MailMerge.Execute

objDoc.Close False

objWord.ActiveDocument.SaveAs tempRoot & "CertificateRSZ.docx"

Set objDoc = objWord.Documents.Open(Filename:=tempRoot & "CertificateRSZ.docx")


Set objWord = Nothing

Set objDoc = Nothing

由于

1 个答案:

答案 0 :(得分:0)

在打开word文档

之前,将以下代码放入程序中
Dim shell As New shell
shell.MinimizeAll

这将最小化所有打开的应用程序窗口

并在打开word文档后输入此代码。

objWord.Application.WindowState = wdWindowStateMaximize

这将最大化要打开的word文档。