Simple eventlist.add question

S

sonyvale

I hate to ask such a trivial quesiton, but I have tried all permutations I
can think of, and searching the web, MSDN, SDKs, and even using the Event
Monitor, but I can't get an added event to call a VBA procedure. The event
object is still alive, and I have triggered it manually and traced it and
gotten the message:
-invokeAO: Failed to map 'ThisDocument.cmdShapeName' to known Add-on
IS there some trick to running a VBA procedure instead of an external addon?

The code is this:

Public evtPageTurn As Visio.Event 'this is declared earlier in the form

Private Sub UserForm_Initialize()
Dim objWindow As Visio.Window
Dim evtCode As Integer
Dim strProc As String

evtCode = visEvtCodeWinPageTurn 'the event type going to be trapped
strProc = "ThisDocument.cmdShapeName" 'the VBA procedure (it's
correct)
Set objWindow = ActiveWindow
Set evtPageTurn = objWindow.EventList.Add(evtCode, _
visActCodeRunAddon, strProc, "")

-------------------
I know the event object is set up right, it's still in scope and triggering
the event because I see it fire in the immediate trace window, but it keeps
saying that 'ThisDocument.cmdShapeName" doesn't map to known Add-On. But
that procedure does exist in ThisDocument (it's a sub not a function, doesn't
take any args, and is public).
Any thoughts?

(e-mail address removed)
 
K

Kari Yli-Kuha

sonyvale said:
I hate to ask such a trivial quesiton, but I have tried all permutations I
can think of, and searching the web, MSDN, SDKs, and even using the Event
Monitor, but I can't get an added event to call a VBA procedure. The event
object is still alive, and I have triggered it manually and traced it and
gotten the message:
-invokeAO: Failed to map 'ThisDocument.cmdShapeName' to known Add-on
IS there some trick to running a VBA procedure instead of an external addon?

I don't think you can run document VBA code directly.

There is a simple workaround, though - using shape sheet function CALLTHIS()

Somewhere, create a cell with formula "CALLTHIS("ThisDocument.cmdShapeName")"
and from your code use Cell.Trigger to call it.

The macro has to have a Visio.Shape as parameter, e.g.
Public Sub cmdShapeName(ByVal ovShape as Visio.Shape)

/C
 
C

Chris Roth [ Visio MVP ]

It seems to me that you can somehow access the VBA project of a Visio
drawing externally. Some sort of reference - you can even write VBA code to
the drawing...at least this was possible at one time. It may have been
turned off do to security issues.

I think I tried it a while ago and ran into some sort of "Trust blah blah"
problem, but I can't remember the details.

Perhaps another goose to chase at the very least.

--

Hope this helps,

Chris Roth
Visio MVP
 
S

sonyvale

According to the help/sdk you can run VBA procedures from an added event.
For your work-around though how would I run the code to trigger the cell,
since I need the pageturn event to trigger some code in order to trigger the
cell? But since I can't get the pageturn event to actually run any VBA code,
I'm stuck. I suppose I could use the addadvise method since that
automatically calls the VBA event sink class function.
-sonyvale
 
S

sonyvale

But why am I calling it externally? I am calling a VBA function from an
event object in the same scope, no? I mean the event object is
declared/referenced by the same project that it's triying to call a procedure
from. Even if I use the projname.modname.procname syntax to call it, it
doesn't work. I'm using V2000-SR1 by the way, not 2002/3 (need it to work on
legacy Visio as well so using it). I think I'll just do it as an addadvise
and give up on the add method.
thanks for replying!
 

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

Similar Threads


Top