Applying macro to a Button using VBA

Copper Contributor

Hello, 

 

I am trying to apply a macro to a button automatically, 

 

I have successfully managed to do it for the first button, but I don't know why it is not applying for the second button, can anyone help with this, please?

 

Code below:

''''Adding button to Log worksheet''''
Dim RTHPbut1 As OptionButton

ErrorLogWS.Buttons.Add(1725, 25.2, 97.8, 67.8).Select
Selection.OnAction = "ReturnHome"
ErrorLogWS.Shapes("Button 1").Name = "RTHPbut1"
Selection.Name = "RTHPbut1"
Selection.Characters.Text = "Return to Home Page"
Worksheets("Log").Buttons("RTHPbut1").Font.ColorIndex = 33

''''Adding Button to Requests worksheet'''''
Dim RTHPbut2 As OptionButton

RWS.Buttons.Add(577.2, 12.6, 96.6, 70.8).Select

Selection.OnAction = "ReturnHome"
RWS.Shapes("Button 1").Name = "RTHPbut2"
Selection.Name = "RTHPbut2"
Worksheets("Requests").Buttons("RTHPbut2").Text = "Return to Home Page"
Worksheets("Requests").Buttons("RTHPbut2").Font.ColorIndex = 33

 

0 Replies