Skip to content

Instantly share code, notes, and snippets.

@DouglasdeMoura
Created July 2, 2015 14:03
Show Gist options
  • Save DouglasdeMoura/82ac2c27c471d9f3d35a to your computer and use it in GitHub Desktop.
Save DouglasdeMoura/82ac2c27c471d9f3d35a to your computer and use it in GitHub Desktop.
Create a button on Excel spreasheets with VBA
' Usage:
' Call CreateButton("Example", "A1", "name_of_the_macro")
Sub CreateButton(name, rng, theMacro)
With ActiveSheet
Debug.Print .range(rng).Left
Debug.Print .range(rng).Top
.Buttons.Add(.range(rng).Left, .range(rng).Top, .range(rng).Width, .range(rng).height).Select
With Selection
.Characters.Text = name
.OnAction = theMacro
.name = name & rng
End With
End With
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment