Accessing stencil code from toolbar

Started by Sereda, October 02, 2013, 07:21:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Sereda

Hi

I have written some code to analyze data in my Components. I usually place all code in the stencil for easy deployment. When the stencil is opened, it creates a custom toolbar to allow the user to easily run the code through the click of a button. The problem is that I seem unable to access code in the stencil from the toolbar. There is no problem accessing code in the document though. T build and link the toolbar, I'm using:

Private Sub AddButtonToBar(Bar As CommandBar, MacroName As String, Caption As String, Button As Integer)
Dim CmdBarCtrl As CommandBarControl
Set CmdBarCtrl = Bar.Controls.Add(msoControlButton, 1, , , True)
CmdBarCtrl.Style = msoButtonIcon
CmdBarCtrl.FaceID = Button
CmdBarCtrl.Caption = Caption
CmdBarCtrl.OnAction = MacroName
End Sub

If MacroName is located in the document, I can be very diffuse, (enough with the sub name if it is unique), But I dont seem to get it to work if it is in the stencil. This is very strange, because I'm sure I've done it Before (In Another time, at Another job, vith a differnt version of visio (currently I'm using 2013))

I would be greatful for any kind of help...

Best regards
Anders Ă…din
BR
Anders Aadin

Jumpy

Do you have a reference between the VBA project of stencil and document? Otherwise they won't know from another and won't be able to call macros in the other.

Sereda

Hi, I'm kind of a noob, so what do you mean by reference?

In the 'OnAction' parameter, I simply entered the string "MyStencilFileName.MyModuleName.MySubName"

I have a weak recollection that I used an exclamation mark '!' somewhere when I got it to work back in the day, but I dont remember where.

/Anders
BR
Anders Aadin

Jumpy

In the VBA editor you can set references to other libraries or to other VBA-projects. I don't have Visio 2013 and I only have a german version,  so I can't tell you, how to get there. In older versions it's Extras/Options and then Verweise/References?

Sereda

Hi, I Think I solved it.

The OnAction String must be:

"StencilProjecName!ModuleName.SubName"

I knew there needed to be an exclamationmark somewhere, just couldnt remember where. What does the '!' actually mean by the way?
BR
Anders Aadin