Getting program to wait

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
 
K

Ken Tucker [MVP]

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
 

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

Top