Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Allov Allov is offline
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans Tony Jollans is offline
external usenet poster
 
Posts: 1,308
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Allov Allov is offline
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Tony Jollans Tony Jollans is offline
external usenet poster
 
Posts: 1,308
Default 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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting Hidden Text in Word 2007 Michael Moore Microsoft Word Help 1 October 25th 07 03:20 AM
accidently closed out document abarlowa Microsoft Word Help 1 November 12th 06 04:19 AM
How to stop spelling from detecting repeated words? MidnightMaze Microsoft Word Help 1 June 16th 05 02:25 PM
Detecting Wrong MergeFields while automating MailMerge Christof Nordiek Mailmerge 1 April 29th 05 08:48 AM
Detecting view state Kamran Microsoft Word Help 2 January 28th 05 02:29 PM


All times are GMT +1. The time now is 04:19 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"