By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,571 Members | 1,650 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,571 IT Pros & Developers. It's quick & easy.

Getting program to wait

P: n/a
ken
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
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

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

wrd.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(wrd)
GC.Collect()

sFile.MoveTo(CPAPErrorPath & sFile.Name.ToString)
Ken
-------------------
"ken" <an*******@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
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

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.