What I can't find is how to run / reference a macro in a stencil (vss), I
read macros can be stored in stencils so code doesn't get
scattered to every drawing.
So I have a stencil called MyStencil.vss in it a function called MyFunction,
but how do I call this from for example a shapesheet?
If the macro is in the drawing I do: EventDblClick
=runaddon("ThisDocument.MyFunction")
I tried: runaddon("MyStencil.ThisDocument.MyFunction") and
runaddon("MyStencil.MyFunction")
but no success so please some pointers!!!
Another function I want to run when the user presses a button, so I took a
graphic added it to the drawing and then on double click fire the macro, can
this also be done by adding a button to the commandbar? If so some pointers
please...
(I am not on 2002 and have read it's commandbar function, but that is not in
2000)
Thanks in advance,
Michael Dag
Try the function:
CALLTHIS("procedure",["project"],[arg1,arg2,...])
Peter
--
Regards
Peter Suter
Ing.
CH 3255 Rapperswil BE
"Peter Suter" <p.sut...@bluewin.ch> schreef in bericht
news:oprs2mwy...@news.microsoft.com...
On Wed, 30 Jul 2003 01:11:49 +0200, Michael <micha...@hotmail.com> wrote:
> Hi Peter,
> tried your suggestion, but no luck...
> I can't find any references to 'project' should it be:
> "C:\Stencils\MyStencil.vss" ? Or just "MyStencil.vss"
>
"C:\Stencil\MyStencil.vss" or "MyStencil.vss" is wrong! Don't use the path!
Use the projectname.
Make shure, your Stencil is loaded!
You will see the correct projectname in the header of your stencil in the
ShapesWindow or
in the project explorer.
I use - Stencil: "E:\VisioDev\Vss\Dev_Test.vss"
- Projectname: "Dev_Test"
- Modul: "ThisDocument"
- Function: "Test_Call(Byval voShp as Visio.Shape, Byval vsPar1 as String,
Byval vsPar2 as String"
- Call in my Shape: =CALLTHIS("ThisDocument.Test_Call","Dev_Test","1","2")
ok?
Peter
--
Regards
Peter Suter
Ing.
CH 3255 Rapperswil BE
>> Try the function:
Saved it to C:\Stencil.vss
Opened My Document
Opened the Stencil
Can run Hello from the Macro tool button
Added to my shape in the EventFXMod
=CALLTHIS("ThisDocument.Hello","Stencil",)
Move the shape nothing happens...
I do notice that when the formula is entered in the EventFXMod the
,"Stencil", changes to ;"Stencil";
I am getting desperate...
As a last resort could someone send me a sample? all I want is to run my VBA
from a Stencil and not from a Drawing so I can fix or change the code in the
stencil and not go through all Drawings.
Help? ! ? Please...
Michael
"Peter Suter" <p.sut...@bluewin.ch> schreef in bericht
news:oprs358t...@news.microsoft.com...
Sorry, I can't give you my example, because I'm using higher versions.
To bring it to run, there are some tricks to know:
1. Bevore adding your code in stencil, make shure, your Stencil is in EDIT-
mode! (click on the icon at the left of the title bar you should get a
menu that has edit as the second choice. Click on Edit and a red star
should appear on top of the icon in the title bar.)
2. Your Sub must contain the reference (Byval voShape as Visio.Shape)
Public Sub Hello(Byval voShp as Visio.Shape)
MsgBox "Hi 123"
End Sub
3. your projectname in Master has to match the projectname that you can see
in the editor!
4. After changing code in stencil, you have to SAVE the stencil!
Try again!
Peter
--
Regards
Peter Suter
Ing.
CH 3255 Rapperswil BE
If anyone comes across a good document (I ordered Graham's Survival Guide
2000 couple of days ago...) that documents
macros in stencils and how to use them from the shapesheet... think of me
:-) (Microsoft???)
I checked the version and it says Visio 2000 SR1 6.0.2072, so may be there
is a problem there...
Michael
"Peter Suter" <p.sut...@bluewin.ch> schreef in bericht
news:oprs54ya...@news.microsoft.com...
>
>Peter,
>thanks for your patience and advice, unfortunatly this is probably not 'my
>time' yet as it failed again and again,
>so for the moment I'll leave my macros in the drawing and focus on getting
>the logic right rather then where do
>I store my VBA...
Your drawing must contain a Reference to the stencil, before it can refer
to its code in this way. This is only necessary if you want to call
stencil subroutines directly from menu items.
However, this technique doesn't work well in Visio 2000
and appears to break even further in Visio 2002. One problem is
that having a reference will open the stencil but keep it hidden,
and before you know it you end up with multiple copies of the stencil
opened, and what's worse, Visio crashing or making itself invisible.
If there is a foolproof way to use this technique I'm interested to know
how it is done.
One thing you can do in Visio 2000 (not 2002) is automatically inserting
or correcting a reference from the drawing to the stencil.
A quick and dirty way to do it (note that ThisDocument
is the stencil this code is in):
Public Sub AddThisDocumentRef(doc As Visio.Document)
' adds a reference to ThisDocument (i.e. this code) to doc
Dim ref
For Each ref In doc.VBProject.references
If LCase(ref.FullPath) = LCase(ThisDocument.FullName) Then
' we already have the reference we want
Exit Sub
End If
If LCase(right(ref.FullPath, 4)) = ".vss" Then ' any other reference to a Visio stencil
MyDebug.MyPrint "removing code reference in '" & doc.FullName & "' to '" & ref.name & "' to '" & ref.FullPath & "'"
doc.VBProject.references.Remove ref
' in case the reference already existed; but it may be stale,
' e.g. to a different version of the stencil
End If
Next
MyDebug.MyPrint "adding code reference in '" & doc.FullName & "' to '" & ThisDocument.FullName & "'"
doc.VBProject.references.addfromfile ThisDocument.FullName
End Sub
>If anyone comes across a good document (I ordered Graham's Survival Guide
>2000 couple of days ago...) that documents
>macros in stencils and how to use them from the shapesheet... think of me
>:-) (Microsoft???)
>I checked the version and it says Visio 2000 SR1 6.0.2072, so may be there
>is a problem there...
Graham Wideman's book is essential reading on this subject;
it provides a lot of crucial information, clearly presents the
pros and cons of various techniques, and provide working code examples.
>Michael
--
Reinier Post
TU Eindhoven