I tried to create a ribbon in excel and I was successful. Now I have assigned a macro to a button.
Function delete_cells(control As IRibbonControl)
Now, I created another macro, from which I need to call the function delete_cells
. I tried to call it as below.
Function modify_cells(control As IRibbonControl)
delete_cells
End Sub
I am getting an error saying Argument not optional. Please help me with this error.
I suggest that you create a separate subroutine that you call from the button's OnAction and anywhere else you want to call it from, e.g.:
'button macro
Sub cmdDeleteCells_OnAction(control as iRibbonControl)
DeleteCells
End Sub
'another Sub that calls the delete routine
Sub SomeOtherSub
DeleteCells
End Sub
'the one they're all talking about
Sub DeleteCells
msgbox "All your cells are toast, bwah hah hah ha!"
End Sub
EDIT: If you really want to just call the button's OnAction sub, you need to pass it an iRibbonControl object as well, so declare a fake one:
Sub CallTheButtonsCode()
Dim FakeControl As IRibbonControl
cmdDeleteCells_OnAction FakeControl
End Sub
I really don't recommend this for code maintenance reasons, but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With