2014-01-09 97 views
0

我有以下代碼來執行郵件合併使用VBA,郵件合併執行後Word文檔打開最小化,是否有辦法打開正常的文檔(最大化)?Word文檔打開後郵件合併使用msaccess最小化

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 

感謝

+0

請使用代碼按鈕 - {}來設置您的文章的格式。 – Fionnuala

回答

0

將下面的代碼在你的程序中打開Word文檔

Dim shell As New shell 
shell.MinimizeAll 

這將最小化所有打開的應用程序窗口

前,打開後把這個代碼word文檔。

objWord.Application.WindowState = wdWindowStateMaximize 

這將最大化要打開的單詞文檔。