Author Topic: Open a Visio Drawing WITHOUT it's stencils per VBA  (Read 10663 times)

0 Members and 1 Guest are viewing this topic.

MaxKasparek

  • Newbie
  • *
  • Posts: 9
Open a Visio Drawing WITHOUT it's stencils per VBA
« on: September 23, 2014, 07:29:52 AM »
Hi Guys,

i hope i can find some help here regarding the problem touched on this topics subject.

I want to open a Visio drawing per VBA (OpenEx or anything like that) but i don't want that Visio automatically loads the stencils that were used last time working with that document.
Opening the drawing and closing the stencils afterwards is no option because some of my other code has already been stopped from being executed when the "close-all-stencils" method starts (If stencils are open the code won't be executed)

I would really appreciate your help,
thank you and hoping to hear from you,
Max

Surrogate

  • Hero Member
  • *****
  • Posts: 1782
    • ShapeSheet™ Knowledge Base
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #1 on: September 23, 2014, 08:38:16 AM »
Code
Sub CloseVSS()
Dim va As visio.Application, vd As visio.Document, j%
Set va = CreateObject("visio.application")
va.Visible = True
va.AlertResponse = 7
Dim myFile As String
Dim path As String
Dim ext() As Variant
Dim x%, n%
n = 0
path = "i:\plans\" ' this folder contain files names like planN.
If Right(path, 1) <> "\" Then path = path + "\"
ext = Array("*.vsd")
For i = 0 To UBound(ext)
myFile = Dir$(path & ext(i))
While myFile <> ""
myFile = Dir$()
Set vd = va.Documents.Open(path & myFile)
For j = va.Documents.Count To 1 Step -1
If Right(va.Documents(j).Name, 3) = "VSS" Then va.Documents(j).Close ' close file with vss extention
Next j
For j = va.Windows.Count To 1 Step -1
If Right(va.Windows(j).Caption, 4) <> "plan" Then va.Windows(j).Close ' close file which namу not like as planN
Next j
vd.Save
vd.Close
Set vd = Nothing
Wend
Next
va.Quit
Set va = Nothing
MsgBox n
End Sub

Nikolay

  • Hero Member
  • *****
  • Posts: 1245
    • UnmanagedVisio
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #2 on: September 23, 2014, 10:07:42 AM »

MaxKasparek

  • Newbie
  • *
  • Posts: 9
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #3 on: September 23, 2014, 10:12:34 AM »
@ Surrogate Thanks for your reply,

but if i understand this code correctly it loops through all open documents and then closes all *.vss files, so the *.vsd file is the only one still open, right?
That won't work with my code, respectively it could work if i change the code that won't be executed if stencils are open, but this would only work for new files, changing the code in all the old files (that are still used) is impossible (There are over 500 users from around the world that have files where the code had to be changed).

Isn't there a way to open a VISIO drawing completely without stencils? something like openEX(Filename, Flag:OpenWithoutStencils) ?

@Nikolay Also Thanks for your reply,
I tried it with the OpenNoWorkSpace Flag, but with that flag Visio didn't open the drawing.

Nikolay

  • Hero Member
  • *****
  • Posts: 1245
    • UnmanagedVisio
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #4 on: September 23, 2014, 10:28:38 AM »
It looks like visOpenNoWorkspace is exactly the flag you are looking for.. What do you mean by "did not open"? An error appeared, or?
« Last Edit: September 25, 2014, 05:53:58 AM by Visio Guy »

MaxKasparek

  • Newbie
  • *
  • Posts: 9
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #5 on: September 23, 2014, 10:47:45 AM »
I just tried it again with this flag, it looks like this flag makes the drawing invisible (In the VBA Editor i see how the drawing is open, because its listed in open Documents, but i can't see anything else than the code of this document). The flag doesn't prevent the stencils from being loaded, they are just invisible like the drawing itself.

Beside the VBA Editor i see VISIO without an open drawing.
« Last Edit: September 23, 2014, 10:49:35 AM by MaxKasparek »

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #6 on: September 23, 2014, 10:50:14 AM »
I have a question from the sideline if I may:

You're talking about code that is already in the drawings, that won't work if stencils are open. What code is that (VBA?) and how does it start (DocumentOpened-Event?). I understand that you can't change that code but maybe if we could see a little more of your whole picture/problem, we could find another workarround.


MaxKasparek

  • Newbie
  • *
  • Posts: 9
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #7 on: September 23, 2014, 11:06:13 AM »
ok, here is the short story:

At the moment i'm developing a little tool that my firm uses to create offers. The offers include drawings made with Visio.
I made different stencils with custom shapes that represent my firms hardware, from time to time the hardware changes so i change the shapes and the users inside our firm get the new stencils.

Usually everybody creates a new darwing by using the template i made therefore. But in future this will be different. Because i was idiotic and bored enough i told my boss that i could write a .exe and an installation routine for that tool.

The installation routine works fine, also the .exe. The .exe only function is to create new Drawings (start the template) or to load old drawings (open .vsd). But i also want to include a function to let the user choose which stencils he wants (Version 1, Version 2, Version 3, .... all the different Versions that represent the different hardware sets). If the user opens a old drawing by double-clicking on it Visio automatically loads the stencils that were last opened, but i want it to load the stencils that the user chosed in the .exe (registry entry and path). Loading the stencils from the path saved in the registry is no problem but if a user opens an old drawing it looks like this in PseudoCode:

Code
Sub Document_opened()
 If Stencil1.vss is NOT open then
 openex(registrypath/Stencil1.vss)
end if
 If Stencil2.vss is NOT open then
 openex(registrypath/Stencil3.vss)
end if
 If Stencil3.vss is NOT open then
 openex(registrypath/Stencil3.vss)
end if
end sub

The names of the stencils never change, so VISIO always thinks that the stencils are open (they are in fact but only the old versions). If i could find a way to open the drawings without the last stencils being loaded everything would work fine.

I hope you understand what i mean.

Thanks for your help

Nikolay

  • Hero Member
  • *****
  • Posts: 1245
    • UnmanagedVisio
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #8 on: September 23, 2014, 11:36:51 AM »
I just tried it again with this flag, it looks like this flag makes the drawing invisible (In the VBA Editor i see how the drawing is open, because its listed in open Documents, but i can't see anything else than the code of this document). The flag doesn't prevent the stencils from being loaded, they are just invisible like the drawing itself.

Beside the VBA Editor i see VISIO without an open drawing.

It looks like you are using "open hidden" flag (visOpenHidden) instead of "open without workspace".
Sorry for the stupid question, are you sure you are passing visOpenNoWorkspace to the OpenEx function?
It's integer value is 256.

Maybe you could post a code you use to open the drawing?

Nikolay

  • Hero Member
  • *****
  • Posts: 1245
    • UnmanagedVisio
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #9 on: September 23, 2014, 11:44:55 AM »
One more thing, if you want to open a specific version of stencils.

Suppose you have this directory structure:

Version1
 - StencilA.vss
 - StencilB.vss

Version2
 - StencilA.vss
 - StencilB.vss

Version3
 - StencilA.vss
 - StencilB.vss

You can open a drawing with specific set of stencils by setting a .StencilPath property before opening the drawing.
For example, to open with "Version2":

Application.StencilPaths = "C:\<bla-bla-bla>\Version2"
Application.Documents.Open <you file>

About the "visOpenNoWorkspace". It looks you are not programming with VBA, are you?
In this case, make sure the constant value for "visOpenNoWorkspace" is correct. It should be 256
« Last Edit: September 25, 2014, 05:58:04 AM by Visio Guy »

Max-Kasparek

  • Newbie
  • *
  • Posts: 2
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #10 on: September 23, 2014, 01:23:43 PM »
Thats no stupid question but an even more stupid mistake :-D
That happends when you only read for gist H100 =/= 100 -.-, so i used the wrong Flag.

On thursday i'm in the office again and will try it again with the right flag.

Thanks again and Mea Culpa!

Jumpy

  • Hero Member
  • *****
  • Posts: 1061
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #11 on: September 24, 2014, 01:39:57 AM »
Another one from the sidelines:

If 256 works, it's OK.

Othervise Nikolay's suggestion about changing the StencilPath could be a valid way to accomplish your goal.

Last:
If I understand your initial problem, your Document_Opened event didn't fire if the stencils are already loaded? Or what was the problem why you could not close all stencils first? Here may be the problem:
Afaik OpenEvent won't fire if you open a document with Open or OpenEx (at least I had that problem) no matter what you do.


Max-Kasparek

  • Newbie
  • *
  • Posts: 2
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #12 on: September 24, 2014, 10:36:29 AM »
@Nikolay,
at the moment im partly working with VBA and partly working with VB.NET. Yeah i used the wrong value, im trying to test it again tomorrow with 256 as Flag.
Thanks for a second solution

@Jumpy,
in my testing process i added the line:
Code
msgbox "Document_Opened routine works"
If my memory doesnt trick me i think using open or openEx showed this Messagebox. The Problem rather is that inside my Document_Opened routine (in all the old files) there is a query:
Code
 If Stencil1.vss is NOT open then
 openex(registrypath/Stencil1.vss)
end if
 If Stencil2.vss is NOT open then
 openex(registrypath/Stencil3.vss)
end if
 If Stencil3.vss is NOT open then
 openex(registrypath/Stencil3.vss)
end if

I think with the 256er Flag everything should work. I even tried that option before opening up this topic, but as I said before i sadly used 100 as integer instead of the shown H100 as HEX (256 as integer).

MaxKasparek

  • Newbie
  • *
  • Posts: 9
Re: Open a Visio Drawing WITHOUT it's stencils per VBA
« Reply #13 on: September 25, 2014, 03:02:49 AM »
Hey Guys,

thanks all for your help and for not laughing about my idiotic mistake :-D
With the right Flag everything works just fine.

Thanks!