More XRibbon questions

ClimoC

Well-known Member
Joined
Aug 21, 2009
Messages
584
I'm getting there... slowly.

I have no problem with the XML. That's all fine.

My checkBoxes are linked to 3 cells in a data-store sheet. Click the checkbox, and the value is set in the datasheet to true/false, reflecting the checkbox.

But they always start as False. One of the checkboxes I'd like to default to True

Current Ribbon VB code:

Code:
Public MyRibbon As IRibbonUI

Public Declare Sub CopyMemory Lib "kernel32" Alias _
    "RtlMoveMemory" (destination As Any, source As Any, _
    ByVal length As Long)

Public Sub ribb******ed(ribbon As IRibbonUI)
   ' Store pointer to IRibbonUI
   Dim lngRibPtr As Long
' Store the custom ribbon UI Id in a static variable.
' This is done once during load of UI. I.e. during workbook open.
    Set guiRibbon = ribbon
    lngRibPtr = ObjPtr(ribbon)
    ' Write pointer to worksheet for safe keeping
    Thisworkbook.Sheets("GridData").Range("E10").Value = lngRibPtr
    ShwKeyDates = True
End Sub

Function GetRibbon(lngRibPtr As Long) As Object
   Dim objRibbon As Object
   CopyMemory objRibbon, lngRibPtr, 4
   Set GetRibbon = objRibbon
   Set objRibbon = Nothing
End Function

Public Sub RXReFire(Thisribbon As IRibbonUI)
    Set MyRibbon = Thisribbon
End Sub

Public Sub RefreshRibbon()
If Not (MyRibbon Is Nothing) Then

    MyRibbon.Invalidate
    ribb******ed MyRibbon
Else
Set MyRibbon = GetRibbon(CLng(Thisworkbook.Sheets("GridData").Range("E10").Value))
    MyRibbon.Invalidate
    ribb******ed MyRibbon
End If
End Sub

Public Sub GetPressed(control As IRibbonControl, ByRef pressedState)
        Select Case control.ID
                Case "SeriesInSlotChk"
                    If Thisworkbook.Sheets("GridData").Range("D6").Value = "TRUE" Then
                            pressedState = True
                    End If
                Case "ShowKeyDates"
                    If Thisworkbook.Sheets("GridData").Range("D7").Value = "TRUE" Then
                            pressedState = True
                    End If
                Case "ShwKeyDates"
                    If Thisworkbook.Sheets("GridData").Range("E7").Value = "TRUE" Then
                            pressedState = True
                    End If
                End Select
                
End Sub

Public Sub ClickAction(control As IRibbonControl, pressed As Boolean)
        Select Case control.ID
                Case "SeriesInSlotChk"
                    If pressed = True Then
                            Thisworkbook.Sheets("GridData").Range("E6").Value = "TRUE"
                    ElseIf pressed = False Then
                            Thisworkbook.Sheets("GridData").Range("E6").Value = "FALSE"
                    End If
                Case "ShwKeyDates"
                    If pressed = True Then
                            Thisworkbook.Sheets("GridData").Range("E7").Value = "TRUE"
                    ElseIf pressed = False Then
                            Thisworkbook.Sheets("GridData").Range("E7").Value = "FALSE"
                    End If
                Case "EpNumInSlotChk"
                    If pressed = True Then
                            Thisworkbook.Sheets("GridData").Range("E8").Value = "TRUE"
                    ElseIf pressed = False Then
                            Thisworkbook.Sheets("GridData").Range("E8").Value = "FALSE"
                    End If
        End Select
                
                    
End Sub

So I'd assume that either when the Ribbon is invalidated to update, or at least just once during my workbook_open script, I throw in Call somewhere.

Helpy?

Thanks
C
 
Yeah. I was massively wrong. Just chucked someone off another PC and Rory's absolutely correct (erm, predictably I think).

I got it all working with this basic stuff:

(XML)
Rich (BB code):
*customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"*
  *ribbon*
    *tabs*
      *tab id="CustomTab" label="My Tab"*
        *group id="SampleGroup" label="Sample Group"*
          *checkBox id="CheckBoxT" label="True CheckBox" 
  getPressed="GetTrue" /*
          *checkBox id="CheckBoxF" label="False CheckBox"/*
        */group *
      */tab*
    */tabs*
  */ribbon*
*/customUI*

(Code)
Rich (BB code):
Option Explicit
 
Public Function GetTrue(control As IRibbonControl, ByRef pressedstate)
     pressedstate = True
End Function

Apologies for leading you up the wrong path but perhaps this will help now?

Regards
Adam
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
VBE must've capitalised it (I'm assuming it's an object somewhere in the library)

Reverted to pressedState = True

Doesn't change it

Just to clarify, we do know that my checkboxes work fine for setting/getting the True/False when clicked?, it's at either on-Load or during invalidate that I want it to see the value of the cells E6, E7 and E8 and tick/untick as appropriate.

The invalidate/validate works fine for grabbing the GetLabelText1, 2 and 3...
 
Upvote 0
I pasted your code and XML into a workbook and it worked after making those corrections (I skipped the If statements, so perhaps those are causing your problem).

I'm not sure why you would have had XML in your VBE?
 
Upvote 0
Oh Snap... I think I just got it...

There's a case statement for the pressedState bit right?

Well, is the value not going to be set for ALL the checkboxes, using the same getPressed command, for each recheck upon validation?

So wouldn't this be true?:
It starts with control.ID "Checkbox1", goes through the case statement, checks cell E6, decides the pressedState is FALSE, so sets the checkboxes (all of them) to False?
Then does the second one, which is TRUE, sets them all to true, then the final one, FALSE again, they all go back to false?

Its only a theory, but still... If your one works adam, the only difference I see is that you have a bespoke call back for one checkbox. My three checkboxes share the callback and use a case statement.
 
Upvote 0
I pasted your code and XML into a workbook and it worked after making those corrections (I skipped the If statements, so perhaps those are causing your problem).

I'm not sure why you would have had XML in your VBE?

because to paste into the body text, I had to replace all '<'s and '>'s with '*'s, and the find/replace in VBE is easy and quick to use
 
Upvote 0
Doesn't explain why it would replace some but not all...

Anyway, I reinstated your GetPressed function, changed it back to using pressedState, added a GridData sheet and entered TRUE, FALSE, FALSE in the three cells. Reloading the workbook, I get one checked box as expected. The callback is called once for each checkbox.
 
Upvote 0
Ok, sorted it now...

Swapped my GetPressed with case statements for these (and updated the XML too)

Code:
Public Function GetPressedSeries(control As IRibbonControl, ByRef pressedState)
        If Thisworkbook.Sheets("GridData").Range("E6").Value = True Then
                pressedState = True
        Else
                pressedState = False
        End If
End Function
Public Function GetPressedKeyDates(control As IRibbonControl, ByRef pressedState)
        If Thisworkbook.Sheets("GridData").Range("E7").Value = True Then
                pressedState = True
        Else
                pressedState = False
        End If
End Function
Public Function GetPressedEpNum(control As IRibbonControl, ByRef pressedState)
        If Thisworkbook.Sheets("GridData").Range("E8").Value = True Then
                pressedState = True
        Else
                pressedState = False
        End If
End Function

...but it didn't work until I changed my test to specifically test for the boolean value of the cells, rather than the text "TRUE"/"FALSE"

Now, clearly, I wouldn't normally do that (checking the Text), but I think there was a reason for it
 
Upvote 0

Forum statistics

Threads
1,216,216
Messages
6,129,566
Members
449,517
Latest member
Lsmich

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top