Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Releasing Word Object in code

Status
Not open for further replies.

tcode

Programmer
Jan 8, 2004
15
0
0
US
I've created a program that creates envelopes using word by passing in the recipients name. No matter what I've done, I can not get the program to release the word doc. from the system memory. What ends up happening is there are 13 open word documents when the code completes it's course through the recordset. Here's the applicable section of my code (I've commented out what I've already tried):

Dim appWord As Word.Application
'Set appWord = CreateObject("Word.Application.8")
Set appWord = New Word.Application

sFile = App.Path & "\Envelope.doc"
appWord.Documents.Open sFile

appWord.ActivePrinter = gPrinter
appWord.ActiveDocument.Envelope.PrintOut Address:=recip, _
Size:="Size 10", PrintBarCode:=False

'DoEvents

CleanUp:
appWord.Documents(1).Close Savechanges:=wdDoNotSaveChanges 'master document

If Not appWord Is Nothing Then Set appWord = Nothing
Exit Sub

Any help is greatly appreciated!
 
Try using this to close and release the Word Doc:

appWord.DisplayAlerts = wdAlertsNone
appWord.Documents.Close
appWord.Quit
Set appWord = Nothing

Swi
 
Perfect! It releases the process when it executes the appWord.Quit statement.
Thanks so much!
 
No problem. Glad to help.

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top