cannot obtain events after doc.close

S

SHolder

Hi, My code need to open multiple files, say Doc A and Doc B. First I open
Doc A, run some codes, and open Doc B. In DocumentOpened event for Doc B,
I close Doc A, by DocA.close. Once this happens I lost my access to Visio
events.
Does
anyone have any ideas what is happening and what I can do to resolve it?
 
C

Chris [Visio MVP]

Where's your code? In Doc A's VBA project? If so, then of course the code is
unloaded with the doc. If not, then you need to have a Visio Application
object somwhere in your code, and get the Doc_Opened even from that.

If you're using VBA, you'll have to have some sort of "Controller Document"
that doesn't get closed, and directs the whole process, but has nothing to
do with the drawing-data that you are creating or changing. Basically a
code-project container and not a diagram of any sort.
 
G

Guest

Thanks Chris.

I looked into what is happening...looks like the codes in my 2 documents are
referring to the same Visio app object...here is my situation:

I have DocA and DocB with following codes:
---
DocA:
Dim WithEvents vsoApplication1 As Visio.Application
Dim WithEvents vsoWindow1 As Visio.Window
Private Sub vsoApplication1_DocumentSaved(ByVal doc As IVDocument)
MsgBox "Save -- DocA"
End Sub

Private Sub vsoWindow1_BeforeWindowClosed(ByVal Window As Visio.IVWindow)
MsgBox "DocA_BeforeWindowClosed"
End Sub
-----
DocB:
Dim WithEvents vsoApplication2 As Visio.Application
Dim WithEvents vsoWindow2 As Visio.Window
Private Sub vsoApplication2_DocumentSaved(ByVal doc As IVDocument)
MsgBox "Save -- DocB"
End Sub

Private Sub vsoWindow2_BeforeWindowClosed(ByVal Window As Visio.IVWindow)
MsgBox "DocB_BeforeWindowClosed"
End Sub
----

I launched Visio and opened DocA and DocB.
On DocA I hit Ctrl + S to fire DocumentSaved. I see Save -- DocA message
box.
Then on DocB, I hit Ctrl + S...expecting to get Save -- DocB message
box...but I got DocA message box twice.

If I close DocA to fire BeforeWindowClosed, I get "DocA_BeforeWindowClosed"
If I close DocB to fire , I get "DocB_BeforeWindowClosed"

Somehow my events are mixed up!!!
Any help is greatly appreciated!
 
G

Guest

Thanks Chris.

I looked into what is happening...looks like the codes in my 2 documents are
referring to the same Visio app object...here is my situation:

I have DocA and DocB with following codes:
---
DocA:
Dim WithEvents vsoApplication1 As Visio.Application
Dim WithEvents vsoWindow1 As Visio.Window
Private Sub vsoApplication1_DocumentSaved(ByVal doc As IVDocument)
MsgBox "Save -- DocA"
End Sub

Private Sub vsoWindow1_BeforeWindowClosed(ByVal Window As Visio.IVWindow)
MsgBox "DocA_BeforeWindowClosed"
End Sub
-----
DocB:
Dim WithEvents vsoApplication2 As Visio.Application
Dim WithEvents vsoWindow2 As Visio.Window
Private Sub vsoApplication2_DocumentSaved(ByVal doc As IVDocument)
MsgBox "Save -- DocB"
End Sub

Private Sub vsoWindow2_BeforeWindowClosed(ByVal Window As Visio.IVWindow)
MsgBox "DocB_BeforeWindowClosed"
End Sub
----

I launched Visio and opened DocA and DocB.
On DocA I hit Ctrl + S to fire DocumentSaved. I see Save -- DocA message
box.
Then on DocB, I hit Ctrl + S...expecting to get Save -- DocB message
box...but I got DocA message box twice.

If I close DocA to fire BeforeWindowClosed, I get "DocA_BeforeWindowClosed"
If I close DocB to fire , I get "DocB_BeforeWindowClosed"

Somehow my events are mixed up!!!
Any help is greatly appreciated!
 

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