VBA References, for multi-users?

Started by Matrix, May 06, 2010, 11:45:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Matrix

I'm using a vss (stencil) to save the VBA code and from the Visio file VBA making a reference to the vss file and that works good for a single user but when the next user opens a second Visio file that have the same reference file (vss) it fails since the file is already in use by the first user. Any simple solutions of how to enable more than one user to reference (make use of) the same VBA code?

Tommy

geh_heim

hm i think i misunderstood a bit but well

Since i need the same VBA code in about 10 Visio files at the moment i just created a template with the code in it and just use that as start.

i know its stupid if you have to change some part of the code but in my case it is unlikely that anyone will touch the VBA again

Jumpy

But another problem with using a Template to store your VBA Code is, that you send your code whenever you send someone a drawing, and that is unneccassary and often unwanted.

So the method of using the stencil is better in that respect and I plan to use that, too.
Therefore I'm interested, too, in a solution for that problem.

Visio Guy

Your users will have to have the latest copy of the stencil (that contains the code) locally on their machine. It sounds like you are opening the stencil from the network and are having sharing problems?

I wonder if your problem will go away if the stencil is open read-only? (or is it already...?)

The reference to the stencil might also be causing the problem. Why not just make sure the stencil opens with a template and tell your users that closing the stencil IS BAD because the code won't work anymore.

I've had problems with doing an actual reference to a stencil. Maybe these have been fixed in recent releases of Visio, but it used to always crash things for me.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

Jumpy

Another funny thing to that:
When I reference the code in the stencil from the drawing/template, the stencil is opened invisible and is opened visible a second time, if it's part of the template. Therefore I use an empty stencil to store my code and don't make it part of the opened stencils of my drawing/template. So only the invisible version is opened (because of the reference) and the users don't know it is there and so they can't close it by mistake.
I also had problems with saving the code after updates, when both Versions were opened because one is readonly and that's normally (thank Murphy) the one I used to change the code in.

By the way: If the code in the stencil is only started with the Callthis funcion from the ShapeSheet a reference is not needed, because you pass along the VBA projekt name as a parameter.

Visio Guy

#5
Good comment about CALLTHIS! I like using CALLTHIS if the project is definitely going to be done in VBA. It allows you to avoid a lot of cumbersome event-handling code that requires a bunch of initialization, and can easily break if errors occur.

I just tested in Visio 2010: you can add a stencil to a template/drawing by opening it with a VBA immediate window call, like this:

Call Visio.Documents.OpenEx("C:\Users\Some_User\Desktop\test invisible vss in vst\MyStencil.vss", Visio.VisOpenSaveArgs.visOpenHidden)

Edit: The drawing file will NOT remember the stencil and open it. Since I can't find the Workspace option/check-box in Visio 2010, I tried saving the document using the workspace option:

Call Visio.ActiveDocument.SaveAsEx(Visio.ActiveDocument.FullName, Visio.VisOpenSaveArgs.visSaveAsWS)

and that didn't work either. There may be a way to cause hidden stencils to open (other than using references), but I can't find it right now.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

aledlund

which brings to mind is vba thread-safe, i.e. local variables and multiple users changing them.
???
al

Matrix

#7
Is there a way to do the referencing from the code?
I could then at the of the opening the .vsd file copy the vba.vss (that does only have vba code and does not open as a stencil) from the network to the c-drive and make the reference [by code] to the vba.vss on the c-drive.

Well I must at some stage be able to remove the reference, at closing of Visio? I would imagine that the referencing is part of the more deeper functions of VBA and the "VBA" will not be "fooled" by tricks like that.

Just a general comment; since we are doing development in a project as we go (no funding for general development) we do changes when we stumble into problems or just find out a new cool functions (or as we explain to the managers, by adding that function will save many for the project in the long run).

Putting in some comments on the previous answers, and thank you all of you for your time and support.
The vba.vss is on the network and it works very well for one user at the time and individual copies on the c-drive does also work but if on the c-drive we have to spend time distributing revised vba.vss files.
We are doing calls at "Document_DocumentOpened" and it seems that "Document_DocumentOpened" needs the reference meaning that an open stencil is not enough, maybe if we open the stencils first (hidden) and then make the call at "Document_DocumentOpened".
A read only stencil gives errors when it is opened by a reference.

I have to think about CALLTHIS, maybe there us a workaround with CALLTHIS.

Cheers
Tommy

Jumpy

It may be a compromise to store Subs belonging to shapes and therefore called with Callthis in a stencil and others in the template.