Creating a Button that runs a Macro Using VBA

aryaden

Board Regular
Joined
Jun 9, 2021
Messages
101
Office Version
  1. 2019
Platform
  1. Windows
I would like to create a macro that creates a button to run another macro in a specific sheet in a workbook. I have multiple workbooks with a worksheet (same title in all workbooks) that i need to place a "run macro" button in cell B2 for. The button when clicked would run another macro I have already created.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I would suggest creating a Macro that does what you want.
Put that Macro in your Personal Workbook.
And activate the script by using a shortcut Key.
This script would run on any workbook you have open.
No need having a Button to run the script.
 
Upvote 0
I would suggest creating a Macro that does what you want.
Put that Macro in your Personal Workbook.
And activate the script by using a shortcut Key.
This script would run on any workbook you have open.
No need having a Button to run the script.
Thanks for the suggestion but after I make changes I am sending the workbook to a client. I wanted them to be able to make changes and run my macro if needed by clicking a button.
 
Upvote 0
You could loop through the sheets with code like this
VBA Code:
With ActiveSheet
    With .Buttons.Add(184, 57, 120, 30)
        .Top = .Parent.Range("B2").Top
        .Left = .Parent.Range("B2").Left
        .OnAction = "myOtherMacro"
    End With
End With
 
Upvote 0
Solution
You could loop through the sheets with code like this
VBA Code:
With ActiveSheet
    With .Buttons.Add(184, 57, 120, 30)
        .Top = .Parent.Range("B2").Top
        .Left = .Parent.Range("B2").Left
        .OnAction = "myOtherMacro"
    End With
End With
Thank you! I will try that, if I wanted to apply this to a specific worksheet named "Data_1" how would I change the code?
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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