Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Mail merge issue - ghost Excel process remains after closing application

This is how i have done it.

Sub Mail_Merge()

Dim wrd As Word.Application
Dim doc As Word.Document
Dim wrdSelection, wrdMailmerge, wrdMergefields As Object

Set wrd = CreateObject("word.application")
Set doc = wrd.Documents.Add
Set wrdMailmerge = doc.MailMerge
wrdMailmerge.MainDocumentType = wdMailingLabels
wrd.Application.MailingLabel.CreateNewDocument

Set wrdMergefields = wrdMailmerge.Fields
Set wrdSelection = wrd.Application.Selection
Set dSrcField = wrdMailmerge.DataSource.FieldNames

wrd.ActiveDocument.MailMerge.OpenDataSource
Name:="z:\data_for_merge.xls", _
linktosource:=True, _
sqlstatement:="SELECT
title,forename,surname,Add1,Add2,add3,add4,postcod e FROM
`Sheet1$`"

For Each fld In dSrcField
If Not fld Is Nothing Then
Select Case LCase(Left(fld.Name, 3))
Case "add", "pos"
wrdSelection.TypeText vbCrLf
wrdMergefields.Add wrdSelection.Range, fld.Name
Case Else
wrdMergefields.Add wrdSelection.Range, fld.Name
wrdSelection.TypeText " "
End Select
End If
Next fld

wrd.Application.MailingLabel.DefaultLabelName = "L7160"
wrd.WordBasic.MailMergePropagateLabel
wrdMailmerge.Execute
wrd.Visible = True

doc.Close False
Set wrd = Nothing

End Sub


-----Original Message-----
Hi all,
I have seen similar problems in some old threads and

other forums, but
no workable solution so far.

The problem I have is this:

I use Excel worksheet as a data source for Word mail

merge, and I
wrote a sub in Excel VBA to open the word document and

link it to it's
data source, which works fine. But when both Word and

Excel are
closed, there is still an Excel process in the memory, it

shows up on
Task Manager processes list. This ghost process causes

opening failure
for all future instances of Excel, untill it is manually

terminated or
PC is restarted.

The code in question is below.

Sub mergeAndViewLetters()

Application.ScreenUpdating = False
setMergeVariables 'sets all the global variables not

dimensoned
here

Dim sDataFileName As String
Dim sSQL As String
Dim oWApp As New Word.Application
'early binding, requires MS Word Library
Dim docLetterFile As Word.Document

sDataFileName = ThisWorkbook.Name
sSQL = "SELECT * FROM `MergeData$`"

oWApp.Visible = True
Set docLetterFile = oWApp.Documents.Open

(stProjectPath &
stLetterFileName)


docLetterFile.MailMerge.OpenDataSource _
Name:=stProjectPath & sDataFileName, _
LinkToSource:=True, _
Revert:=False, _
Connection:=stProjectPath & sDataFileName, _
SQLStatement:=sSQL


docLetterFile.Activate

'tidy up - release references
Set docLetterFile = Nothing
Set oWApp = Nothing

End Sub



I made an attempt at releasing all the references. I even

tried
closing the data source or pointing it to a non-Excel

dummy data
source on closing of the Word document (not in this

version of the
code) - none of that worked.

There was a suggestions to use only fully qualified

references to
Excel objects, I might try that, but it will not be easy

and there is
no guarantee that I won't miss something.



Need urgent guru intervention...
Thank you
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel 2003: mail merge issue shanna Excel Discussion (Misc queries) 3 December 31st 08 10:46 PM
Excel program remains open after closing file RPC Excel Discussion (Misc queries) 9 February 7th 08 07:59 PM
mail merge-word file automatically closing vishu Excel Discussion (Misc queries) 3 October 24th 05 05:03 PM
Mail merge issue - ghost Excel process remains after closing application d_b Excel Programming 0 August 16th 04 01:12 AM
Excel process remains running Josh[_5_] Excel Programming 2 September 11th 03 04:22 PM


All times are GMT +1. The time now is 11:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"