Question

I am trying to add an extra tab to the Word ribbon and have a couple buttons to invoke my own macros. I did the same thing with Excel and it worked fine. For some reason I can't get it to work in Word. I am using the Custom UI Editor. Here's the ribbon code.

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
 <ribbon startFromScratch="false">
  <tabs>
   <tab id="customTab" label="Pavel">
    <group id="customGroup" label="Formatting">
 <button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="Callback" />
</group>
   </tab>
  </tabs>
 </ribbon>
</customUI>

Just a very simple tab, with one button that calls the macro Callback().

I added a module to the Word file with the following code.

Sub Callback()
  MsgBox ("Test")
End Sub

The macro runs fine on its one (hitting the play button in the editor) but when invoked via the button on the tab I get the following error:

enter image description here

Edit: It seems to do something with 1) public access to the module and 2) apparently the macro should be taking some argument similar to "control as ribboncontrol" or something like that. If you know where to find the documentation for this, please let me know.

Was it helpful?

Solution

A Ribbon button expects a Sub which takes a parameter:

Sub Callback(button As IRibbonControl)
  MsgBox ("Test")
End Sub

http://msdn.microsoft.com/en-us/magazine/cc163469.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top