|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB.NET and Microsoft Word problem: topic becomes read-onlyDim WordApp As New Word.Application Try WordApp.Documents.Open(CType("C:\Temp\mydoc.doc", Object)) etc. -- etc. -- etc. Return True Catch ex As Exception Return False Finally Try WordApp.Documents.Close() WordApp.Quit() Catch ex As Exception End Try End Try This code works fine unless I crash somewhere in the etc part of the code and the Finally never triggers properly. In this case, the file becomes locked in a read-only mode. I can't delete it, edit it, or rename it regardless of what I try short of rebooting. The only way I can get it released is to reboot. Is there something that can be done to get it unlocked without rebooting? Hi
Is it possible to deal with it in your exception handling code (assuming this gets called ok if the code 'crashes')? I.e. Close the document and Word if an exception is caught? Just an idea Thanks Martin genojoe wrote: Show quoteHide quote > I am opening a Word document with code like this: > > Dim WordApp As New Word.Application > Try > WordApp.Documents.Open(CType("C:\Temp\mydoc.doc", Object)) > etc. -- etc. -- etc. > Return True > Catch ex As Exception > Return False > Finally > Try > WordApp.Documents.Close() > WordApp.Quit() > Catch ex As Exception > End Try > End Try > > This code works fine unless I crash somewhere in the etc part of the code > and the Finally never triggers properly. In this case, the file becomes > locked in a read-only mode. I can't delete it, edit it, or rename it > regardless of what I try short of rebooting. The only way I can get it > released is to reboot. Is there something that can be done to get it > unlocked without rebooting? Right now, this is a problem during debugging. If I stop debugging somewhere
during the etc, etc, etc. I am stuck rebooting to get rid of my test file. I was hoping for a way to avoid rebooting. If I could only remember not to stop the debugging until after executing the Finally........ That's another story. My memory for details like that sucks. I suspect after a few reboots, my memory will suddenly get better. In run time, I suspect your suggestion would work. Also, knowledge of how to recover from such a file might prove useful sometime in the future. It seems there should be a way to kill an orphan Word file like that without a reboot. Show quoteHide quote "Pritcham" wrote: > Hi > > Is it possible to deal with it in your exception handling code > (assuming this gets called ok if the code 'crashes')? I.e. Close the > document and Word if an exception is caught? > > Just an idea > > Thanks > Martin > Hi
Have you checked the running processes in Task Manager to see if instance of Word that you fired up is still there - it may well be (as it hasn't been shut down) and if that's the case, that ('hidden' instance of Word) may be the reason that the file is locked as it's already being modified. Just an idea Cheers Martin genojoe wrote: Show quoteHide quote > Right now, this is a problem during debugging. If I stop debugging somewhere > during the etc, etc, etc. I am stuck rebooting to get rid of my test file. > I was hoping for a way to avoid rebooting. > > If I could only remember not to stop the debugging until after executing the > Finally........ That's another story. My memory for details like that > sucks. I suspect after a few reboots, my memory will suddenly get better. > > In run time, I suspect your suggestion would work. Also, knowledge of how > to recover from such a file might prove useful sometime in the future. It > seems there should be a way to kill an orphan Word file like that without a > reboot. > > "Pritcham" wrote: > > > Hi > > > > Is it possible to deal with it in your exception handling code > > (assuming this gets called ok if the code 'crashes')? I.e. Close the > > document and Word if an exception is caught? > > > > Just an idea > > > > Thanks > > Martin > > |
|||||||||||||||||||||||