excelvbacallbackribbon-controlribbonx

Purpose Built-in Control, but with error: Wrong number of arguments or invalid property assignment


I was trying to repurpose a built-in control. Using similar RibbonX code and VBA code, I found that some controls can be repurposed (for examples, Paste and FileSave), and some cannot be repurposed (for examples, Bold and Underline). The error message was "Wrong number of arguments or invalid property assignment".

RibbonX code:

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <commands>
        <command idMso="Underline" enabled="false"/>
        <command idMso="Bold" onAction="MyBold"/>
    </commands>
</customUI>

In a standard VBA module:

'Callback for Bold onAction
Sub MyBold(control As IRibbonControl, ByRef cancelDefault)
    MsgBox "Hello"
End Sub

In Excel when I clicked on the Bold control, I got the error message:

Wrong number of arguments or invalid property assignment

Searching the internet for examples this site and another site, do not provide me any clue.

Really appreciate your thoughts. Thank you.


Solution

  • You have the wrong callback signature. See this document: https://msdn.microsoft.com/en-us/library/aa722523%28v=office.12%29.aspx?f=255&MSPPError=-2147217396

    The Bold button is in fact a togglebutton control, so you should be using:

    Sub MyBold(control As IRibbonControl, pressed As Boolean, ByRef cancelDefault)
    
    End Sub