Set word = nothing takes a looong time

  • Thread starter Betina Y Andersen
  • Start date
B

Betina Y Andersen

I have a VB6 app that uses vba against Word 2000.

When I runs the line Set WordObj = Nothing it takes from 1 minut up to 10
minutes to get freed from memory.

This problem has come as I have added some code to one of my procedures, I
have added the following

FilNavn = Mid(CStr(VisWord), 7, Len(CStr(VisWord)) - 6)
WordObj.Selection.WholeStory
WordObj.Selection.Copy
WordObj.Documents.Add
WordObj.Selection.Paste
WordObj.ActiveDocument.SaveAs FileName:=FilNavn
WordObj.ActiveDocument.Close
WordObj.Selection.HomeKey

Then I return to VB and does some code before calling another procedure
that
end Word:

WordObj.ActiveDocument.PrintOut Background:=False
WordObj.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
WordObj.Quit
Set WordObj = Nothing

It is the last line that takes up all my CPU and uses from 1 munute and up
to complete.

What can I do to speed this up, cos it is unbearable to sit and wait for it
to complete and I use this a lot in my VB app?

Regards Betina
 
D

Doug Robbins - Word MVP

Hi Betina,

Would you mind letting us in on the solution?

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
 
B

Betina Y Andersen

Sure, I had a suggestion from Cindy to try the following:
Dim doc1 as Word.Document, doc2 as Word.Document
Dim FilNavn as String

Set doc1 = WordObj.ActiveDocument
FilNavn = Mid(CStr(VisWord), 7, Len(CStr(VisWord)) - 6)
Set doc2 = WordObj.Documents.Add
doc2.Range.FormattedText = doc1.Range.FormattedText
doc2.SaveAs FilNavn
doc2.Close wdDoNotSaveChanges
Set doc2 = Nothing
'Whatever
doc1.PrintOut Background:=False
doc1.Close wdDoNotSaveChanges
Set doc1 = Nothing
WordObj.Quit wdDoNotSaveChanges
Set WordObj = Nothing

And it did the trick, why I do not know.

\Betina
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top