Adding Color and Changing Font of a Button made using VBA

aryaden

Board Regular
Joined
Jun 9, 2021
Messages
101
Office Version
  1. 2019
Platform
  1. Windows
I currently have code to create a button that goes into A1 and I would like to change the color and font of the button. How can I add to my existing code to do so?

My Current Code:

VBA Code:
Sub CreateButton()
Dim btn As Button
Dim t As Range

Application.ScreenUpdating = False
ActiveSheet.Buttons.Delete

Set t = ActiveSheet.Range(Cells(1, 1), Cells(1, 1))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)

With btn
.OnAction = "Button" 'Runs Macro Button 
.Caption = "Run Macros"
.Name = "Button"

Application.ScreenUpdating = True

End Sub

Thanks for any help in advance!
 
In that case you can use
VBA Code:
Sub CreateButton()
Dim btn As Shape

Application.ScreenUpdating = False

On Error Resume Next
Sheets("Data_1").Shapes("Button").Delete
On Error GoTo 0

With Sheets("Data_1").Range("A1")
   Set btn = .Worksheet.Shapes.AddShape(1, .Left, .Top, .Width, .Height)
End With
With btn
   .OnAction = "Button" 'Runs Macro Button
   .TextFrame.Characters.Caption = "Run Macros"
   .Fill.ForeColor.RGB = rgbDarkBlue
   .TextFrame.Characters.Font.Color = vbWhite
   .Name = "Button"
End With
Application.ScreenUpdating = True

End Sub
Is the macro you want to run simply called Button?
I got it to work! I realized I had not saved it as a macro enabled workbook and since I was using macros from my personal workbook it was having some issues.

Thank you so much for the help!
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,889
Messages
6,122,097
Members
449,065
Latest member
albertocarrillom

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