Re: Set word = nothing takes a looong time by Betina
Betina
Mon Jul 07 06:35:46 CDT 2003
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
"Doug Robbins - Word MVP" <dkr@mvps.org> skrev i en meddelelse
news:OIhbktHRDHA.3700@tk2msftngp13.phx.gbl...
> 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
> "Betina Y Andersen" <byl@egdatainform.dk> wrote in message
> news:u78Be5GRDHA.1624@tk2msftngp13.phx.gbl...
> > Problem resolved.
> >
> >
> > "Betina Y Andersen" <byl@egdatainform.dk> skrev i en meddelelse
> > news:eVz0IoSQDHA.2432@TK2MSFTNGP10.phx.gbl...
> > > 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
> > >
> > >
> >
> >
>
>