Search notes:

Excel Object Model: Button

A button object executes a macro when the user clicks on the button.
The button object is hidden (like, for example, the Global object).

Adding a button and assigning a macro

option explicit

sub main() ' {

  '
  ' Use a range to determine the coordinates where
  ' the button will be placed:
  '
    dim dest as range
    set dest = range( cells(4,2), cells(5,3) )

  '
  ' Create/add the button.
  '
    dim btn as button
    set btn  = activeSheet.buttons.add( left := dest.left, top := dest.top, width := dest.width, height := dest.height)
    btn.caption  = "Click me!"

  '
  ' Assign a macro (sub) to the button:
  '
    btn.onAction = "btnClicked"

end sub ' }

sub btnClicked() ' {

    msgBox "The button was apparently clicked"

end sub ' }
Github repository about-MS-Office-object-model, path: /Excel/Button/add.bas
See also some general notes on the onAction property of form controls

See also

The Creating a CommandButton with an OLEObject.
Form controls
Excel Object Model

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Microsof...', 1743249577, '3.22.71.103', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Microsoft/Office/Excel/Object-Model/Button/index(87): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78