Consulting

Results 1 to 3 of 3

Thread: callback an EditBox in the Ribbon

  1. #1

    callback an EditBox in the Ribbon

    Hi,

    I'm trying to link the EditBox value in a personal ribbon to a macro (file in attach). I'm a basic VBA user, the codes were found on internet and adapted, however something is missing and I have no clue!?

    Anybody can help?

    Thanks
    cpmsimoes
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    That's good for "a basic VBA user"

    I think you over-complicated it: too many variables and 99% identical subs

    I changed your CustomUI

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    <ribbon>
    <tabs>
    <tab id="MyTab" label="Operators" >
     <group id="MyGroup" label="Group Operators">
      <editBox id="EditBox" label="Without Label" onChange="SetNumberValue" sizeString="WWWWWW" showLabel="false"/>
      <box id="box1" boxStyle="horizontal">
        <button id="bMultiply" label="X" size="normal" onAction="Action" />  
       <button id="bDivide" label="/" size="normal" onAction="Action" /> 
      </box>
      <box id="box2" boxStyle="horizontal">
       <button id="bAdd" label="+" size="normal" onAction="Action" /> 
       <button id="bSubtract" label="-" size="normal" onAction="Action" /> 
      </box>
     </group>
    </tab>
    </tabs>
    </ribbon>
    </customUI>
    and simplified your callbacks

    Option Explicit
    
    Public RibbonTextBox As String
    
    'Callback for EditBox onChange
    Sub SetNumberValue(control As IRibbonControl, text As String)
         RibbonTextBox = text
    End Sub
    
    'Callback for bMultiple, etc. onAction
    Sub Action(control As IRibbonControl)
        Dim xValue As Double
        Dim c As Range
        
        If Not TypeOf Selection Is Range Then Exit Sub
        
        If Not IsNumeric(RibbonTextBox) Then
            MsgBox "Error! The value entered '" & RibbonTextBox & " is NOT a NUMBER."
            Exit Sub
        End If
        
        xValue = CDbl(RibbonTextBox)
        
        For Each c In Selection.Cells
            If IsNumeric(c.Value) Then
                Select Case control.ID
                    Case "bMultiply": c.Value = c.Value * xValue
                    Case "bDivide": c.Value = c.Value / xValue
                    Case "bAdd": c.Value = c.Value + xValue
                    Case "bSubtract": c.Value = c.Value - xValue
                    Case Else
                        MsgBox control.ID & " not found"
                End Select
          End If
        Next c
        
    End Sub
    so give this a shot
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Wow! Thank you so much, Paul. It's working like I wanted. Great!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •