Getting program to wait

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using VB.Net to process information out of a word document. If the document fails a test, I would like to close it and move it to an error folder. However, when I try to do that (see below) it says that another process is using the document. Is there some way to force the move to wait for the doc to close?
Thanks.

Dim wrd As Word.Application = New Word.Application
Dim doc As Word.Document

For Each sFile In Files
strName = CPAPDataPath & sFile.ToString
doc = wrd.Documents.Open(strName)

*** Processing Here ***
If...
*** Processing Here ***
Else
wrd.Quit()
sFile.MoveTo(CPAPErrorPath & sFile.Name.ToString)
End If
 
Hi,

Try this. You need to use marshal.releasecomobject to get word to
close.

wrd.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(wrd)
GC.Collect()

sFile.MoveTo(CPAPErrorPath & sFile.Name.ToString)


Ken
 
Back
Top