CustomUI ribbon button to trigger VBA Function?

Started by kedas, December 07, 2010, 08:00:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kedas

Hi,

I added two buttons in this tab in a CustomUI XML but the onAction doesn't trigger the VBA function
I tried to call a VBA function and even a msgbox should work but I get nothing when I press the buttons.
I imported the attached file via the import method in the ribbon edit window but later it will be done by .Net code.
Since it has to work with old documents I can't add new VBA code to make it work.

Anyone with experience knows how to make this work?

Quote<mso:tab id="mso_c1.7A43D5" label="SPX">
       <mso:group id="mso_c1.7FA5E2" label="SPX" autoScale="true">
         <mso:button id="LeaveDesign" onAction="=Thisdocument.UIhide2.Applicationhide()" label="Leave System Design" size="large" />
         <mso:button id="Verify" onAction="=MsgBox(123)" label="Verify System Design" size="large" />
       </mso:group>
       <mso:group id="mso_c2.7A43D5" label="View &amp;&amp; Print" autoScale="true">
         <mso:control idQ="mso:PanAndZoomWindow" visible="true"/>
         <mso:control idQ="mso:PrintPreviewWholePage" visible="true"/>
         <mso:control idQ="mso:FilePrint" visible="true"/>
       </mso:group>
     </mso:tab>

Thanks

I got some info from here:
http://www.utteraccess.com/forum/Events-firing-Ribbon-Cl-t1943192.html&pid=1967453&mode=threaded#entry1967453

kedas

#1
Hi, I found the problem:  :)
Correct syntax is just the name (with or without module name) of the (public) sub or function AND must be present in a module.

Quote<mso:group id="mso_c1.7FA5E2" label="SPX" autoScale="true">
         <mso:button id="LeaveDesign" onAction="UIhide2.Applicationhide" label="Leave System Design" size="large" />
         <mso:button id="Verify" onAction="mybutton" label="Verify System Design" size="large" />
</mso:group>

Quotein VBA: (in a module)
Sub mybutton()
   MsgBox "Button was clicked!"
End Sub

I have one sub that is not present in a module.  :(
So if you know what the right syntax is to get to those 'thisdocument' subs I would appreciate the help??

(No I can't move the sub, it are older vsd files that now also have to work with Visio 2010)

kedas

never mind
This works: onAction="ThisDocument.SubName"  :)

Luckily I was also subscribed to this forum to give answers  ;D

kedas

#3
I still have a problem:
When I import the ribbon xml with the import function in visio then it works but in code it doesn't work the same way.
<mso:button id="Verify" onAction="ThisDocument.VerifyVisioInput" label="Verify System Design"

1) Import with Visio interface (on application level)
VBA:
Public Sub VerifyVisioInput() this works

2) VB.Net import/load  with (on document level) Targetdoc.CustomUI=StreamReader("ribbon2.xml").ReadToEnd()  Save and reopen to take effect.
VBA:
Public Sub VerifyVisioInput() now it doesn't work? (missing argument error)
Public Sub VerifyVisioInput(Control As IRibbonControl) this works

So I have two questions:
1) Does anyone know how to make this work in VB.net?
(I do not want to install an add-in on the users PC and I cannot add the 'Control' argument since it are old documents)
It must be possible since it works when visio imports the xml ribbon?

2) Is there a way to make the new CustomUI ribbon active without having to save, close and reopen the file? I can't make RegisterRibbonX work without add-in.

Thanks