power4XL Microsoft Excel Resource Center
Free Macros, Formulas, Functions, Tutorials, Downloads, Add-Ins & More!

Launch a VBA function or macro from within a worksheet (3 of 3):
Embed a custom command button in your worksheet

ShareThis

Perhaps the most useful technique for launching your VBA code from within Excel is to embed a "Start" button directly in your worksheet:

In Excel 2007 this is done with the Insert command on the Developer tab in the Ribbon:

In Excel 2003, make sure the Control Toolbox is open by selecting it from the View - Toolbars dropdown menu:

Then select the Command Button from the Control Toolbox:

In both Excel 2007 and Excel 2003, the next step is to drawn the button on your worksheet by dragging with your mouse.  In Excel 2007, the Assign Macro dialogue opens automatically after you have drawn the button.  In this case you can assign your Monte Carlo function name directly to the button without having to create a subroutine which calls the function.

In Excel 2003, double clicking the button while it is in Edit mode will open the VB Editor displaying a new subroutine associated with the button.  Type the name of your Monte Carlo function in the subroutine, then save the file.

The downloadable Examples worksheets contain embedded "start" buttons for each included VBA function.

 

 

Prev | Contents | Next

Copyright notice:  This site and all content, including computer code and spreadsheet examples, are copyright 2006 by Fritz Dooley.  License is granted for individual users to download examples and to copy code directly into user's spreadsheets and Visual Basic for Applications files.  Users may not redistribute code in any way.  Providing hyperlinks to this web site is encouraged, but posting code and examples on other web sites is expressly forbidden.  "Microsoft" is a registered trademark of Microsoft Corporation.   Neither this web site nor Fritz Dooley is affiliated with Microsoft Corporation.