Search code examples
vbaexcel-2010ribbonexecute

Execute VBA from Excel 2010 Ribbon


I have been trying different examples of how to move my VBA buttons into the ribbon but either I the text is flagging red(aka error) or examples relate to doing some xml conversions (never done before so they make no sense).

All I want to do is move my text coloring buttons into my custom ribbon. When the user clicks on the button icon(inside the Ribbon), the VBA coding executes.

enter image description here

As you can see above, currently the Text-Green button on the ribbon... when the user clicks it.. it generates a blank Command Button for User to create new Command Buttons. Clearly not what I want.

Any suggestions?

My Blue and Red button coding (simple coding):

Private Sub Color_Blue_Click()
    Selection.Font.Color = RGB(83, 141, 213)
End Sub

Private Sub Color_Red_Click()
    Selection.Font.Color = RGB(255, 0, 0)
End Sub

enter image description here

I have tried referencing:

http://www.rondebruin.nl/win/section2.htm


Solution

  • Wow I guess it was a simple fix afterall:

    I went to:

    Developer Tab/Record Macro

    Named the Macro as TextGreen.... clicked Ok and once it was saved I clicked Stop Recording

    Went back to Developer/Code Tab and clicked on Macros

    Then I clicked Edit and typed my code there:

    Sub TextGreen()
    
      Selection.Font.Color = RGB(0, 176, 80)
    
    End Sub
    

    enter image description here

    To save to ribbon I did:

    Right click Ribbon/Customize Ribbon... Selected Macros from drop down...saved a group under my Ribbon Tab and Added it.