PDA

View Full Version : Solved: Cannot run Ribbon callbacks



prof
11-26-2008, 06:07 AM
I've successfully created one Ribbon-activated workbook.
My second, copied pasted and adapted from the first, into an existing workbook, is not working for a strange reason. Saved as .xlsm etc.
Macros are enabled but message 'Cannot run the macro 'Guess2.xlsm!ribbonLoaded': macro ... not available or ... disabled'. Strangely, the message appears twice. The ribbon is loaded but its controls, when used, report similar messages.
I added the workbook name to the callbacks but it did not work either way.

XML is created using the CustomUI editor, and is well formed:
<?xml version="1.0"encoding="utf-8" ?>
<customUI onLoad="Guess2.xlsm!ribbonLoaded"xmlns="#usual link - not allowed to post this# " >
<ribbon>
<tabs>
<tab id="GuessTab"label="Guess!" >
<group id="Tournament"label="Tournament" >
<button id="btnTournament"label="Start tournament"imageMso="ViewBackToColorView"supertip="Start Tournament"size="large"onAction="Guess2.xlsm!StartTournament" />
</group>
<group id="Game"label="Game" >
<button id="btnGame"label="Start game"imageMso="MacroPlay"supertip="Start game"size="large"onAction="Guess2.xlsm!StartGame" />
</group>
<group id="grpGuess"label="Guess" >
<button id="btnGuess"label="Guess"imageMso="TentativeAcceptInvitation"supertip="Guess"size="large"onAction="Guess2.xlsm!Enter_Guess" />
</group>
<group id="GuessBox"label="GuessBox">
<labelControl id="lblEditBox"label="Enter Guess"/>
<box id="myBox"boxStyle="horizontal">
<editBox id="eb1"label="lblGuess"sizeString="m"showLabel="false"getText="Guess2.xlsm!eb1_init"onChange="Guess2.xlsm!eb1_onChange"/>
<button id="ConfirmButton"showLabel="false"imageMso="AcceptInvitation"size="normal"label="Confirm Guess"onAction="Guess2.xlsm!ebConfirmGuess"/>
</box>
<labelControl id="lc1"label="Check to confirm"/>
</group>
<group id="ListBoxControls"label="ListBox Controls" >
<comboBox id="cb1"label="Combo items"getItemCount="cb1_ItemCount"getItemLabel="cb1_ItemLabel"onChange="Guess2.xlsm!cb1_onChange"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>

VBA is in module RibbonControlMacros within the workbook as normal:
Dim MyRibbon As IRibbonUI
'Callback for customUI.onLoad
Sub ribbonLoaded(ribbon As IRibbonUI)
Set MyRibbon = ribbon
End Sub
'Callback for cb1 getItemCount
Sub cb1_ItemCount(control As IRibbonControl, ByRef returnedVal)
returnedVal = 10
End Sub
'Callback for cb1 getItemLabel
Sub cb1_ItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
returnedVal = index
End Sub
'Callback for cb1 onChange
Sub cb1_onChange(control As IRibbonControl, text As String)
Range("Guess") = text
Enter_Guess
End Sub
'Callback for eb1 getText
Sub eb1_init(control As IRibbonControl, ByRef returnedVal)
returnedVal = ""
End Sub
'Callback for eb1 onChange
Sub eb1_onChange(control As IRibbonControl, text As String)
Range("Guess") = text
End Sub
'Callback for ConfirmButton onAction
Sub ebConfirmGuess(control As IRibbonControl)
Enter_Guess
End Sub

Other macros refer to Module1 (content deleted for brevity):
' Guess2 macros
'Option Explicit
Dim Game_Finished As Boolean
Sub Auto_Open()
Randomize 'one-off command to initialise a random number stream
Start_Tournament
' MsgBox ("Welcome to Andrew's Great Guessing Game!")
End Sub
Sub Start_Tournament()
End Sub
'
Sub Start_Game()
End Sub
Sub Enter_Guess()
End Sub

Sub Input_Box_Guess()
End Sub
Sub Spin_box_guess()
End Sub
Sub Pop_Up_Guess()

End Sub

Any suggestions please?

prof
11-26-2008, 11:10 AM
The answer is in the VBA Tools | References, where Microsoft Office12 Object Library was not checked.
(it was in the other working model, and indeed when checked addresses the problem)