Set a macro as a shape method?

E

Ed

I'd like to attach a macro to a shape that I can invoke from VBA, say, to
print custom property values. (In the end, I hope to have different versions
of a macro associated with evolving verions of a shape in a template.)

I have macros assigned to action rows in the shapesheet. I can find and
print the value of the action action. I just can't figure out how to get it
to DO the action.

I've also tried variations of the following code:

Sub test1()
MsgBox "Hi Ed"
End Sub

Sub test2()
runmacro "test1"
End Sub

but get "Sub or function not defined" errors for whatever function name I
try (including runmacro, docmd, and evaltext). If I could invoke from a
string, I'd just slap a macro name as text in a custom propertyan ddeclare
victory.

Am I missing something simple?
 
J

JuneTheSecond

Second prog should be read as
Sub test2()
test1
End Sub

RunMacro function would be used in the shapesheet of your shape.
Put RunMacro("test1") in EventDblClick cell in Events section.
 
E

Ed

Thanks, but that's not quite the question I was asking. Let me try again.

I have some methods defined for the shape that I've associated with actions
in the shapesheet. Cool. Get to them by right clicking. Life is good.

I'd like a similar mechanism so that I could treat a shape as an object with
methods, assigned to the master object, and available programmatically, I've
already got the macro associated with a row of the action section. I can
even find that row and list the action, something like:

Public Function doObjectAction(obj As Visio.Shape, propertyName As String)
Dim row As Long

If obj.CellExists("Actions." + propertyName, 0) Then
row = obj.Cells("Actions." + propertyName).row
Debug.Print obj.CellsSRC(visSectionAction, row , visActionAction).Formula
End If
End function

I just can't get it to do the action programmatically. As you say, it seems
that runmacro and the like only work in the shapesheet, although that's far
from clear in the help file.

Again, this seems like something so basic that I hope I'm just missing a
simple way to do it.

Thanks,
Ed
 
J

JuneTheSecond

You might try Triger method.
obj.CellsSRC(visSectionAction, row, visActionAction).Trigger
 

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