Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Detecting a closed document
Hi,
I'm having trouble detecting if a document has been closed using .Net and the Word Object Library 12.0. Imagine a wraper for the : Public Class WordWraper Private word As New Word.Application() Private doc As Word.Document = word.Documents.Open("C:\test.doc") Public Sub SaveAndClose() doc.Save() doc.Close() End Sub Public Sub Dispose(...) ' Some verification of the object to check if it exists or not equals nothing. doc.Close() ' Here, it will crash with error RPC_E_DISCONNECTED. doc = Nothing End Sub End Class In the dispose method, it's going to crash if the object has been closed before. I could put a flag "hasBeenClosed" in this class and test this flag before doing the last close operation, but I'm hoping there's a way to check for that in the API itself? Thanks a lot Allov |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Detecting a closed document
Why not just check for doc = nothing?
-- Enjoy, Tony "Allov" wrote in message ... Hi, I'm having trouble detecting if a document has been closed using .Net and the Word Object Library 12.0. Imagine a wraper for the : Public Class WordWraper Private word As New Word.Application() Private doc As Word.Document = word.Documents.Open("C:\test.doc") Public Sub SaveAndClose() doc.Save() doc.Close() End Sub Public Sub Dispose(...) ' Some verification of the object to check if it exists or not equals nothing. doc.Close() ' Here, it will crash with error RPC_E_DISCONNECTED. doc = Nothing End Sub End Class In the dispose method, it's going to crash if the object has been closed before. I could put a flag "hasBeenClosed" in this class and test this flag before doing the last close operation, but I'm hoping there's a way to check for that in the API itself? Thanks a lot Allov |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Detecting a closed document
Yeah, I wasn't clear enough with my comment, should have put the check for
null values. So, yeah, I do check for Nothing, and this is why I'm asking for a solution here because the object does NOT equal nothing when it has been closed, and when I try to close it a *second* time (like in the dispose function), it gives me the mentionned errorl. So the code should read: If doc IsNot Nothing Then doc.Close() ' -- Crashes when closing a second time. doc = Nothing "Tony Jollans" wrote: Why not just check for doc = nothing? -- Enjoy, Tony "Allov" wrote in message ... Hi, I'm having trouble detecting if a document has been closed using .Net and the Word Object Library 12.0. Imagine a wraper for the : Public Class WordWraper Private word As New Word.Application() Private doc As Word.Document = word.Documents.Open("C:\test.doc") Public Sub SaveAndClose() doc.Save() doc.Close() End Sub Public Sub Dispose(...) ' Some verification of the object to check if it exists or not equals nothing. doc.Close() ' Here, it will crash with error RPC_E_DISCONNECTED. doc = Nothing End Sub End Class In the dispose method, it's going to crash if the object has been closed before. I could put a flag "hasBeenClosed" in this class and test this flag before doing the last close operation, but I'm hoping there's a way to check for that in the API itself? Thanks a lot Allov |
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Detecting a closed document
I don't know the syntax of whatever language you are using so will have to
assume that is correct. The most common reason for this sort of problem is implicit instantiation somewhere. To identify where that might be we would need to see all the code. -- Enjoy, Tony "Allov" wrote in message ... Yeah, I wasn't clear enough with my comment, should have put the check for null values. So, yeah, I do check for Nothing, and this is why I'm asking for a solution here because the object does NOT equal nothing when it has been closed, and when I try to close it a *second* time (like in the dispose function), it gives me the mentionned errorl. So the code should read: If doc IsNot Nothing Then doc.Close() ' -- Crashes when closing a second time. doc = Nothing "Tony Jollans" wrote: Why not just check for doc = nothing? -- Enjoy, Tony "Allov" wrote in message ... Hi, I'm having trouble detecting if a document has been closed using .Net and the Word Object Library 12.0. Imagine a wraper for the : Public Class WordWraper Private word As New Word.Application() Private doc As Word.Document = word.Documents.Open("C:\test.doc") Public Sub SaveAndClose() doc.Save() doc.Close() End Sub Public Sub Dispose(...) ' Some verification of the object to check if it exists or not equals nothing. doc.Close() ' Here, it will crash with error RPC_E_DISCONNECTED. doc = Nothing End Sub End Class In the dispose method, it's going to crash if the object has been closed before. I could put a flag "hasBeenClosed" in this class and test this flag before doing the last close operation, but I'm hoping there's a way to check for that in the API itself? Thanks a lot Allov |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Detecting Hidden Text in Word 2007 | Microsoft Word Help | |||
accidently closed out document | Microsoft Word Help | |||
How to stop spelling from detecting repeated words? | Microsoft Word Help | |||
Detecting Wrong MergeFields while automating MailMerge | Mailmerge | |||
Detecting view state | Microsoft Word Help |