How do I activate a stencil that is already open?

J

Jason V

Thanks. However when I try it I get an error. Here is what I am after.
The following code works but it opens ABC.vss, but I already have it open.
How can I modify this to just activate the one that is open and drop a shape
from it?
Public Sub TestDropShapeX()
Dim stencil As Visio.Document, mstCircle As Visio.Master
Set stencil = ThisDocument.Application.Documents.Open("d:\...\ABC.vss")
ThisDocument.Application.Windows(ThisDocument.Index).Activate
Set mstCircle = stencil.Masters("ee") ' Get the master named "ee" and drop
that shape on the page!
ThisDocument.Pages(1).Drop ShapeName, 6, 6
End Sub

Thanks
 
J

John Goldsmith

Hello Jason,

Have a go with this:

Public Sub TestDropShapeX()
Dim stencil As Visio.Document
Dim mstCircle As Visio.Master
Dim vDoc As Visio.Document
Dim sStencilPath As String
Dim sStencilName As String
Dim sStencil As String
Dim shpNew As Visio.Shape

sStencilPath = "d:\"
sStencilName = "ABC.vss"

'Check if the stencil is already open...
For Each vDoc In Application.Documents
If vDoc.Name = sStencilName Then
Set stencil = vDoc
End If
Next vDoc
'...if not, open it
If stencil Is Nothing Then
sStencil = sStencilPath & sStencilName
Set stencil = Documents.OpenEx( _
sStencil, visOpenDocked)
End If

'Note - Activating the stencil is not required
'to drop the shape
ActiveWindow.Windows.ItemEx(stencil.Title).Activate

Set mstCircle = stencil.Masters("ee")
Set shpNew = ThisDocument.Pages(1).Drop(mstCircle, 6, 6)

End Sub

If you have any errors let me know on which line and what they say.

Hope that helps.

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
J

Jason V

Thanks. I got this to work however I had to rem out the line of code
ActiveWindow.Windows.ItemEx(stencil.Title).Activate
this gave me the error
Invalid window type for this action.

In regards to not needing to activate the stencil and the stencil is already
open along with others how does it know which stencil the shape is in? When I
executed the previous code I supplied w/o specifically opening a new stencil
even with a current one open I got an error on this line
Set mstCircle = stencil.Masters("ee")
object variable not set.

One more thing. I am opening Visio from excel and keeping Vision Hid
(transparent to the user). Problem is it comes up with the "do you want to
enable macros?". Is there anyway to get rid of this as I would like it to be
totally transparent to the user?
 
J

John Goldsmith

Morning Jason,

Answers are below.

Best regards

John


John Goldsmith
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk

Jason V said:
Thanks. I got this to work however I had to rem out the line of code
ActiveWindow.Windows.ItemEx(stencil.Title).Activate
this gave me the error
Invalid window type for this action.

My mistake. A more robust method would be to replace that line with the
following:

'Note - Activating the stencil is not required
'to drop the shape
Dim wdw As Window
Application.Windows(ThisDocument.Index).Activate
For Each wdw In ActiveWindow.Windows
If wdw.Document.Name = sStencilName Then
wdw.Activate
Exit For
End If
Next wdw
In regards to not needing to activate the stencil and the stencil is
already
open along with others how does it know which stencil the shape is in?
When I
executed the previous code I supplied w/o specifically opening a new
stencil
even with a current one open I got an error on this line
Set mstCircle = stencil.Masters("ee")
object variable not set.


That's because you didn't set the reference to the stencil object first.
You need to get the stencil by either finding it already open or opeing a
new one and set a reference in either case. If you see my code below that's
what happens. When you declare an reference type object (Dim stencil as
Visio.Document) its value at that point is 'Nothing', so if our first run
('Check if the stencil is already open...) doesn't find the stencil, then
"stencil = Nothing". The second part checks whether that's the case. (If
stencil Is Nothing then open a new version.)

One more thing. I am opening Visio from excel and keeping Vision Hid
(transparent to the user). Problem is it comes up with the "do you want to
enable macros?". Is there anyway to get rid of this as I would like it to
be
totally transparent to the user?

You can surpress some dialogs but not that one as it depends on the user's
security settings. If you're running from Excel though, do you need to have
any code in the Visio document?

Hope that helps.

John
 
J

Jason V

Thanks John. I understand this better now.

In regards to your answer to my last question. Myabe I don't need any code
in Visio. I would rather not I just did't know how. What I am doing is
getting information from a user in excel and then drawing the object in
visio, and then copying it back to the excel form transparent to the user and
they can see their system get built and then if they need to later modify the
visio file. I am calling a routine in Visio but I quess I could have all of
that code in excel? correct? I just didn't think about that.
 

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