SuperMaximus
Programmer
I have read all of the similar threads and haven't found a solution of the problem of Excel.exe process running in Task Explorer after closure of both Word & Excel Applications.
As you see in the code below I've set WordApp and WordDoc both to 'Nothing' at the end of macro.
This macro invokes the procedure of Merge Data (from also opened in this macro Merge-source DOC file with mergefields), asks user to save the result of Merge and then closes both source and result files.
This macro is being called from Excel.
As the result, I always see 'Excel.exe' process running in the memory even when I close Excel and Word Applications either.
If I change all the code related to Word Merge Procedure to smth like MsgBox "Hello", everything goes right and excel.exe process terminates when applications close...
Consequently, the problem hides in impossibility of explicit Word file closure. This is my assumption.
You can try to invoke the Merge procedure yourself by the similar scheme and you'll be surprised when you face the same problem.
Please, help me to comprehend this difficulty and to get rid of unnecessary 'Excel.exe' running...
p.s. I also used early binding instead Set WordApp = CreateObject("Word.Application") - it didn't help.
Thanks in advance!
As you see in the code below I've set WordApp and WordDoc both to 'Nothing' at the end of macro.
Code:
Option Explicit
Sub RunContract_Automation()
'Dim Fs As Variant
Dim ContractPath As String
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim CType As String, CFile As String
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open _
(ThisWorkbook.Path & "\" & CFile)
WordApp.Visible = True
With WordApp.Application
'=========macro of Merge procedure==========
.ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
.ActiveDocument.MailMerge.OpenDataSource name:=ActiveDocument.Path & "\WORK.xls", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=WORK.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=35;Je" _
, SQLStatement:="SELECT * FROM Import$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
.ActiveDocument.MailMerge.Destination = wdSendToNewDocument
.ActiveDocument.MailMerge.SuppressBlankLines = True
.ActiveDocument.MailMerge.DataSource.FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
.ActiveDocument.MailMerge.DataSource.LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
.ActiveDocument.MailMerge.Execute Pause:=False
'=============================================================
With .Dialogs(wdDialogFileSaveAs)
.name = "D:\NEW\" & ContractName
.Show
End With
' .Quit SaveChanges:=wdDoNotSaveChanges
End With
WordApp.Quit SaveChanges:=wdDoNotSaveChanges
Set WordApp = Nothing
Set WordDoc = Nothing
End Sub
This macro invokes the procedure of Merge Data (from also opened in this macro Merge-source DOC file with mergefields), asks user to save the result of Merge and then closes both source and result files.
This macro is being called from Excel.
As the result, I always see 'Excel.exe' process running in the memory even when I close Excel and Word Applications either.
If I change all the code related to Word Merge Procedure to smth like MsgBox "Hello", everything goes right and excel.exe process terminates when applications close...
Consequently, the problem hides in impossibility of explicit Word file closure. This is my assumption.
You can try to invoke the Merge procedure yourself by the similar scheme and you'll be surprised when you face the same problem.
Please, help me to comprehend this difficulty and to get rid of unnecessary 'Excel.exe' running...
p.s. I also used early binding instead Set WordApp = CreateObject("Word.Application") - it didn't help.
Thanks in advance!