Michael
Michael

Reputation: 11

VBA Word Custom Ribbon does not effect Macros

I've written a few subroutines in VBA to do some things in Word that I want it to do. It works as intended. However, when I created a custom ribbon for it, using the Office RibbonX Editor and generated callbacks, nothing happens when the associated button is pressed. Here is the xml schema for the ribbon:


<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon startFromScratch="false" >

<tabs>
    <tab id="Ribbon1" label="Custom Ribbon">
    <group id="Group_1" label="Common" autoScale="true">
        <button id="btn1" label="DoThis" imageMso="AppointmentColor10" onAction="RibbonControl.DoThis" visible="true"/>
        <button id="btn2" label="DoThis1" imageMso="BlackAndWhiteWhite" onAction="RibbonControl.DoThis1" visible="true"/>
    </group>
    </tab>
    </tabs>
    </ribbon>
    </customUI>

Callbacks are generated like this:

'Callback for btn1 onAction
Sub DoThis(control As IRibbonControl)
End Sub

'Callback for btn2 onAction
Sub DoThis1(control As IRibbonControl)
End Sub

I have tried different modification of the >onAction< attribute, but between getting VBA errors and buttons not working, this is the point I'm stuck in.

I'd appreciate any tips on how to solve it.

Upvotes: 0

Views: 193

Answers (1)

HackSlash
HackSlash

Reputation: 5812

In my working Ribbon XML I am not using a module name, just calling the method directly. So your XML code should look like this:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <ribbon startFromScratch="false" >
        <tabs>
            <tab id="Ribbon1" label="Custom Ribbon">
                <group id="Group_1" label="Common" autoScale="true">
                    <button id="btn1" label="DoThis" imageMso="AppointmentColor10" onAction="DoThis" visible="true"/>
                    <button id="btn2" label="DoThis1" imageMso="BlackAndWhiteWhite" onAction="DoThis1" visible="true"/>
                </group>
            </tab>
        </tabs>
    </ribbon>
</customUI>

For these methods to be reachable from the Ribbon some things must be true:

  1. The code must exist in a regular Module. Not a class module, form, or any other object. Make a module called "RibbonActions" or something and put them all there.

  2. The methods must be public, your subs are implicitly public so that should work but I like to add the Public keyword just to be explicit about it.

  3. The signature must match the event, which yours does appear to fit the pattern.

Upvotes: 0

Related Questions