VBA Code to Extract Text from the Button/Macro I select

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
421
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for your assistance.

I have two macro buttons which I have assigned to the same macro. What I would like to do is modify how the macro is run when selecting the macro. So for example, let's say:

First Macro Button
Button Name: Button1
Text within Button1 - "Download"

Second Macro Button
Button Name: Button2
Text within Button1 - "Upload"

If I select Button1, the Macro will extract the text and run the Macro in 1 Scenario, but if I select Button2, the Macro will run in an alternate scenario.

For example

Rich (BB code):
Sub MacroButtonRun()

Dim MacroString as text

'Get the text from the Macro button I select where the text will be MacroString

If MacroString = "Download" Then
    'do this
ElseIf MacroString = "Upload" Then
   'do this
Else
  MsgBox "Possible "Error!"
End If

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You mean like this?

VBA Code:
Sub MacroButtonRun()
    Dim MacroString As String
    
    MacroString = ActiveSheet.Buttons(Application.Caller).Caption
    
    MsgBox MacroString
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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