Visio 2002 CALLTHIS Method not working

L

landlord172

Could anyone help with this?
I've tried this method/function in the EventDblClick cell of the Events
section of a "Desktop PC" shapes Shapesheet like so :-

(EventDblClick Cell)
=CALLTHIS("testsub()")

I've put the corresponding Subroutine in a Module in VBA like so :-

(VBA)
Public Sub testsub(oShape as Visio.Shape)
MsgBox("Got to testsub")
End Sub

I get no response whatsoever, if I double click the shape to which I've
attached this. I've tried it with and without 'oShape as Visio.Shape', but
it still doesn't work.

If I change the EventDblClick cell to =RUNADDON("testprj.Module1.testsub")
and leave out the oShape argument then it works OK.

I'd like to get the CALLTHIS to work because it passes a 'shape object
reference' to the subroutine, which is very useful.

This is my first message/question to this site, so hello to everyone. It
seems like a friendly, helpful and knowledgable site.

Thanks in anticipation

Paul
 
S

sonyvale

Do this:
=CALLTHIS("testsub",)
(yes, put in the comma, and get rid of the parenthesis)
If your testsub is not in thisdocument, then put in the module name before
it as you did for the runaddond as:
=CALLTHIS("module1.testsub",)
hope that helps.
-sonyvale
 
L

landlord172

Sonyvale, thanks for the info, it didn't work at first but after trying
combinations I got it to work as this :-

(Shapesheet EventDblClick)
=CALLTHIS("ThisDocument.shape_DblClick",)

(VBA "ThisDocument")
Public Sub shape_DblClick(oShp As Visio.Shape)
frmProperties.Show
End Sub

My next question is how do I pass oShp into the frmProperties UserForm? or
should I post this as a new question?

Thanks again

Paul
 
L

landlord172

Sonyvale, thanks for the info, it didn't work at first but after trying
combinations I got it to work as this :-

(Shapesheet EventDblClick)
=CALLTHIS("ThisDocument.shape_DblClick",)

(VBA "ThisDocument")
Public Sub shape_DblClick(oShp As Visio.Shape)
frmProperties.Show
End Sub

My next question is how do I pass oShp into the frmProperties UserForm? or
should I post this as a new question?

Thanks again

Paul
 
S

sonyvale

Simple, what function or object do you want to pass it into? From within
the shape_DblClick procedure you can use the oShp any way you want. It's a
visio shape object which you defnied as named "oShp". So to pass it into a
function in frmProperties, do this:
frmProperties oShp
assuming you declared frmProperties as:
public sub frmProperties(objSomename as Visio.Shape)
 
S

sonyvale

[tried posting a reply but failed - trying again]
Do you want to pass it into a function, sub, or just make an object it? In
the shape_DblClick sub procedure below, you defined the visio shape "oShp" as
the shape object for that procedure, so use it as you would any other object.
For example, to pass it into a sub procedure in the frmProperties, do this:
Public Sub shape_DblClick(oShp As Visio.Shape)
frmProperties.Show
frmProperties.mysub oShp
End Sub

That's assuming you had this in the frmProperties code:
Public Sub mysub(objShpName as Visio.Shape)
'do stuff here with objShapeName
End Sub

If you want to pass it into an object in frmProperties, then assuming you
declared an object called "objPubShape" as a public shape object in the
frmProperties, then you would assign it like this:
Public Sub shape_DblClick(oShp As Visio.Shape)
frmProperties.Show
set frmProperties.objPubShape = oShp
End Sub

That's assuming you had this in the decalration section of frmProperties:
Public objPubShape as Visio.Shape

And there are about a thousand other things you can do with it of course -
it's just normal VB code really.
-sonyvale
 
L

landlord172

Sonyvale, I apologise if I've misunderstood or not explained very well, but
frmProperties is a userform not a function or sub. I want to pass a
variable from a sub in ThisDocument into a sub in the userform. Like so:

(ThisDocument)
Public Sub shape_DblClick(oShp as Visio.Shape)
setShape oShp
frmProperties.Show ' Show userform
End Sub

(Userform frmProperties)
General Declarations
Public oShape As Visio.Shape

Public Sub setShape(ByVal oS As Visio.Shape)
Set oShape = oS
End Sub

VBA complains that the Sub or Function is undefined. The only way I can
get it to work is to create a public variable in a Module which is
effectively Global, but I want to restrict it's scope as much as
possible.

Paul
 
L

landlord172

Sonyvale,
I got this message after posting my previous. Thanks that's sorted it
out.

Public Sub shape_DblClick(oShp As Visio.Shape)
frmProperties.setShape oShp
frmProperties.Show
End Sub

Paul
 
L

landlord172

Sonyvale,
I got this message after posting my previous. Thanks that's sorted it
out.

Public Sub shape_DblClick(oShp As Visio.Shape)
frmProperties.setShape oShp
frmProperties.Show
End Sub

Paul
 
C

Corey McCord

Hoping I can get some help and maybe continue this post in hopes someone
else is having the same problem.

First I can't get examples from previous post unless I use RUNADDON()
instead of CALLTHIS().

This isn't a problem as long as it works, I guess?

Now to the larger problem.

It works if I make the call RUNADDON("ThisDocument.a") with the following
code in the open document. But I need to embed the code in a stencil.

RUNADDON("StencilName.ThisDocument.a") is what I figured I need to do to run
the same code but when I do I get;

Runtime error 424
Object Required

This is the code in StencilName.ThisDocument

Sub a()

On Error GoTo ErrorB

Dim Visio As Object
Set Visio = GetObject(, "Visio.Application")

Dim shpObj As Visio.Shape
Set shpObj = Visio.ActiveWindow.Selection.Item(1)

MsgBox "Ugh" & shpObj.Name

ErrorB:
Debug.Print "Error"
Exit Sub

End Sub

I think I know what's happening but I don't know how to fix it.

Thanks,

Corey
 

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