Chapter 13. Using Embedded Controls

You've seen many ways to run macros, including using keyboard shortcuts, the Macro dialog box, and the Visual Basic Editor. This lesson shows you how to execute VBA code by clicking a button or other object that you can place onto your worksheet to make your macros easier to run.

WORKING WITH FORMS CONTROLS AND ACTIVEX CONTROLS

A control is an object such as a Button, Label, TextBox, OptionButton, or CheckBox that you can place onto a UserForm (covered in Lessons 18, 19, and 20) or embed onto a worksheet. VBA supports these and more controls, which provide an intuitive way for you to run your macros quickly and with minimal effort.

There are two generations of controls. Forms controls are the original controls that came with Excel starting with version 5. Forms controls are still fully supported in all later versions of Excel, including Excel 2010. Forms controls are more stable, simpler to use, and more integrated with Excel. For example, you can place a Forms control onto a Chart sheet, but you cannot do that with an ActiveX control.

Generally, ActiveX controls from the Control Toolbox are more flexible with their extensive properties and events. You can customize their appearance, behavior, fonts, and other characteristics. You can also control how different events are responded to when an ActiveX control is associated with those events.

Forms controls have macros that are assigned to them. ActiveX controls run procedures that are based on whatever ...

Get Excel® VBA: 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.