Applying macro to a Button using VBA

%3CLINGO-SUB%20id%3D%22lingo-sub-2334771%22%20slang%3D%22en-US%22%3EApplying%20macro%20to%20a%20Button%20using%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2334771%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20apply%20a%20macro%20to%20a%20button%20automatically%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20successfully%20managed%20to%20do%20it%20for%20the%20first%20button%2C%20but%20I%20don't%20know%20why%20it%20is%20not%20applying%20for%20the%20second%20button%2C%20can%20anyone%20help%20with%20this%2C%20please%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECode%20below%3A%3C%2FP%3E%3CP%3E''''Adding%20button%20to%20Log%20worksheet''''%3CBR%20%2F%3EDim%20RTHPbut1%20As%20OptionButton%3C%2FP%3E%3CP%3EErrorLogWS.Buttons.Add(1725%2C%2025.2%2C%2097.8%2C%2067.8).Select%3CBR%20%2F%3ESelection.OnAction%20%3D%20%22ReturnHome%22%3CBR%20%2F%3EErrorLogWS.Shapes(%22Button%201%22).Name%20%3D%20%22RTHPbut1%22%3CBR%20%2F%3ESelection.Name%20%3D%20%22RTHPbut1%22%3CBR%20%2F%3ESelection.Characters.Text%20%3D%20%22Return%20to%20Home%20Page%22%3CBR%20%2F%3EWorksheets(%22Log%22).Buttons(%22RTHPbut1%22).Font.ColorIndex%20%3D%2033%3CBR%20%2F%3E%3CBR%20%2F%3E''''Adding%20Button%20to%20Requests%20worksheet'''''%3CBR%20%2F%3EDim%20RTHPbut2%20As%20OptionButton%3C%2FP%3E%3CP%3ERWS.Buttons.Add(577.2%2C%2012.6%2C%2096.6%2C%2070.8).Select%3C%2FP%3E%3CP%3ESelection.OnAction%20%3D%20%22ReturnHome%22%3CBR%20%2F%3ERWS.Shapes(%22Button%201%22).Name%20%3D%20%22RTHPbut2%22%3CBR%20%2F%3ESelection.Name%20%3D%20%22RTHPbut2%22%3CBR%20%2F%3EWorksheets(%22Requests%22).Buttons(%22RTHPbut2%22).Text%20%3D%20%22Return%20to%20Home%20Page%22%3CBR%20%2F%3EWorksheets(%22Requests%22).Buttons(%22RTHPbut2%22).Font.ColorIndex%20%3D%2033%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional 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