PDA

Click to See Complete Forum and Search --> : problem during printing word doc from vb


arunendra
May 20th, 2005, 10:53 AM
I've used bookmarked msword from my vb application to print documents.
after printing

Dim wordapp As New Word.Application
Dim thisdoc As New Word.Document
Set wordapp = Nothing
Set thisdoc = Nothing
Set thisdoc = wordapp.Documents.Open("D:\I B A PRODUCT\Manual Joining Letter.doc", ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", Format:=wdOpenFormatAuto)

'temp_name comes from a database table

If thisdoc.Bookmarks.Exists("name1") = True Then
thisdoc.Bookmarks("name1").Select
' wordapp.ActiveDocument.Bookmarks("name1").Start
wordapp.Selection.TypeText temp_name
End If
wordapp.ActiveDocument.PrintOut Range:=wdPrintCurrentPage
intmsg = MsgBox("Did the document print correctly", vbYesNo)
If intmsg = vbNo Then
intmsg = MsgBox("Do you want to try again printing join details?", vbYesNo)
If intmsg = vbYes Then
wordapp.Documents.Close (wdDoNotSaveChanges)
wordapp.Quit
end if

but after certain no of printing windows virtual memory becomes low as i can see in the task manager several no of winword.exe which are feeling up the memory.
Is there any way to free memory and destroy winword.exe from memory as soon as the printing is complete!

westconn1
May 21st, 2005, 09:22 AM
try after wordapp.quit
set wordapp = nothing
set thisdoc = nothing


pete

RobDog888
May 21st, 2005, 09:38 AM
Also, thisdoc.Close. By using the "wordapp.Documents.Close (wdDoNotSaveChanges)" you are not closing and
destroying the thisdoc object. This is the main issue most office developers miss and end up with multiple instances of their office app.

Are you calling this code every time you print? If so you can optimise it by only opening, printing, and closing the document. Move
your app object to the general declarations section to the top. Then upon loading of your app you open the word app and keep it hidden if needed.

Then upon button click you only need to open the doc, etc.