Creating Custom Workbook Elements
Creating Custom Workbook Elements
In Excel, you can create and modify custom workbook elements such as themes, color
formats, font formats, cell styles, macros, and form controls. Options for customizing cell
styles, themes, colors, and fonts are located on the Home and Page Layout tabs of the
Ribbon. You must add the Developer tab to the Ribbon to access commands for creating
macros and inserting form controls.
Creating and Modifying Custom Themes
A document theme is a predefined set of colors, fonts, and effects that can be applied to
a workbook. You can use document themes to easily format an entire document and give
it a fresh, professional look. Themes are also used in other Office applications, such as
Microsoft Word and Microsoft PowerPoint, enabling you to give all your Office
documents a uniform look in terms of colors, fonts, and effects. (Effects, such as shadows
or bevels, modify the appearance of an object.)
Excel has several predefined document themes. When you apply a theme to a workbook,
the colors, fonts, and effects contained within that theme replace any styles that were
already applied to cells or ranges. You can modify predefined themes to create a custom
theme.
Figure 2-15: The Themes gallery with a preview of the Savon theme displayed
in the worksheet
7. Click Sheet2. Notice that the font changed on that sheet as well.
8. Click Sheet1 to return to the main worksheet. Click the Home tab, and then in the
Styles group, click the Cell Styles button to display the Cell Styles gallery. Notice
that the color schemes for the various groups have changed. This is because a new
1 de 12 14/04/2021, 14:32
OneNote [Link]
document theme has been applied, and several built-in cell styles were created
using theme fonts and colors.
9. Click the Page Layout tab, and then in the Themes group, click the Colors button.
Excel displays a variety of color schemes that you can apply to the current Savon
design theme. Point to Red Orange to display a preview of the new colors in the
worksheet (Figure 2-16).
Figure 2-16: The Colors gallery with a preview of the Red Orange color scheme
displayed in the worksheet
10. From the Colors menu, click the Red Orange option. The fill colors in rows 2 and 3
have changed, but the fonts on both worksheets remain the same.
11. SAVE the 02 Themes [Link] workbook and then CLOSE the workbook.
PAUSE. LEAVE Excel open for the next exercise.
The default document theme in Excel 2016 is named Office. Document themes are
consistent in all Microsoft Office 2016 programs. Applying a new theme changes fonts
and colors, and the color of shapes and SmartArt, tables, charts, and other objects.
Remember that cell styles are used to format specific cells or ranges within a worksheet;
document themes are used to apply sets of styles (colors, fonts, and fill effects) to an
entire document.
Many built-in cell styles use theme-aware formatting, so applying a new theme
determines which fonts and colors are used by styles. That’s why you noticed a change in
the Cell Styles gallery after applying the new theme in the exercise. However, styles are
independent from themes in that you can change styles regardless of the theme that’s
applied to a document.
Take Note When you apply a heading cell style to text and then increase the font size
of that cell, the font size will not change after applying a new document theme. If you
don’t change the font size of heading text, apply a heading cell style, and then apply a
new theme, the heading text will display in the default font size for the new theme.
2 de 12 14/04/2021, 14:32
OneNote [Link]
Take Note In addition to modifying color schemes using the Create New Theme Colors
dialog box, you can use the Colors dialog box to apply a specific custom color in your
worksheet. To do so, select the More Colors option from a color palette (such as the Fill
Color or Font Color palette). Select a color option on the Standard tab or click the
Custom tab and refine your color choice. The Custom tab also enables you to select
specific RGB or HSL values if you want to match a color exactly, such as a color in a
company logo.
3 de 12 14/04/2021, 14:32
OneNote [Link]
Figure 2-20: Use the Style dialog box to create and modify custom cell styles
6. With B5 selected, click the Cell Styles button on the Home tab and select MyStyle
at the top of the gallery. Your new style is applied to cell B5.
7. After applying the cell style, you decide to remove the italic formatting from the
custom style. Click the Cell Styles button on the Home tab, right-click MyStyle at
the top of the gallery, and select Modify. The Style dialog box opens.
4 de 12 14/04/2021, 14:32
OneNote [Link]
8. Click the Format button. In the Format Cells dialog box, click the Font tab, and in
the Font style list, click Bold.
9. Click OK two times to close both dialog boxes. Cell B5 now displays the modified
style without italics.
10. SAVE the 02 Music Sales [Link] workbook and then CLOSE the workbook.
PAUSE. LEAVE Excel open for the next exercise.
Take Note When you create custom themes, color formats, font formats, and cell styles,
the custom settings display as a separate option at the top of the Themes, Colors, Fonts,
and Cell Styles galleries, respectively. You can use these galleries to apply the custom
settings to new areas of your workbook. If you want to delete a custom option, right-click
the option in the applicable gallery and click Delete.
Take Note Excel records only those steps that have a direct impact on the contents of
the worksheet. To be accurate, it records the impact those steps have, not the actual
commands that led to the impact. For example, if you select several rows and columns,
Excel records the act of the rows and columns being grouped. But if you expand or
collapse that group, it does not record that action because doing so does not impact the
worksheet itself. Exceptions include filtering and sorting ranges and tables, which Excel
does record.
5 de 12 14/04/2021, 14:32
OneNote [Link]
Troubleshooting If you make a mistake during the macro recording, don’t worry.
Click Stop Recording in the Code group of the Developer tab. Then start again from
step 7. Use the same name, and when Excel asks whether you want to overwrite the
existing macro with the same name, respond with Yes.
6 de 12 14/04/2021, 14:32
OneNote [Link]
Be careful not to make any other changes to the code. Your screen should appear
similar to Figure 2-23.
Figure 2-23: Modifying the CustomSubtotals macro in the Visual Basic for
Applications window
27. In the menu bar at the top of the window, click File and then select Close and
Return to Microsoft Excel.
28. In the worksheet, delete rows 20 and 21. You will test the macro using the assigned
shortcut key and ensure that the macro modification works correctly.
29. Select cell D20 and then press Ctrl+Shift+S. The macro runs and the result in cell
E20 appears in bold rather than italic formatting.
30. Click the File tab and then click Save As. Select a folder or click Browse to navigate
to the folder where you are saving your files.
31. In the Save As dialog box, under Save as type, choose Excel Macro-Enabled
Workbook (*.xlsm). Save the workbook as 02 Revenues [Link] in the
lesson folder on your flash drive. Click OK if a message box displays after you save
the file.
PAUSE. LEAVE the workbook open to use in the next exercise.
Take Note For security reasons, Excel no longer saves macros in its regular .XLS and
.XLSX file formats. Now, the only way to save a macro-enabled workbook is to give it the
special .XLSM file type. This way, companies that want to avoid any possibility of
spreading malware can enforce policies preventing .XLSM files from being attached to or
received within e-mails.
Because of the proliferation of malicious software, Microsoft has set up Excel so that after
it’s installed, you cannot execute macros from a file you open (even an explicitly macro-
enabled workbook) until you read the notification and click Enable Content. If you never
plan to run macros or if you’re skeptical about any of your office colleagues, you can turn
off macros completely. You can also turn off the notifications and enable all macros, if
you work in an office such as a financial services provider where macros are in use
constantly, you trust the source of the Excel workbooks, and notifications would only get
in the way.
7 de 12 14/04/2021, 14:32
OneNote [Link]
Take Note Try using a Form control first. If you find that you need a property that the
Form control cannot offer, try the ActiveX version. Note that many of the ActiveX controls
on the Developer tab’s Insert menu are from the MS Forms library. That library is external
to Excel and must be loaded. This is one of the fundamental differences between the
Form controls, which are built in to Excel, and any ActiveX controls.
Both types of controls offer the ability to link input (populate a list) and output (show
what was selected) between the control and a worksheet cell.
Note that both Form controls and ActiveX controls float on the worksheet. This means
that like shapes, you can tell Excel whether you want to move and/or resize your controls
as you insert, delete, or resize rows and columns.
A basic listing of the available form controls includes the following:
8 de 12 14/04/2021, 14:32
OneNote [Link]
9 de 12 14/04/2021, 14:32
OneNote [Link]
K6 [Link].F
G6 [Link].X
K4 [Link].F
K8 [Link].F
G11 [Link].X
G23 lnk.Option1.X
G25 lnk.Option2.X
G27 lnk.Option3.X
K20 [Link].F
G8 [Link].X
15. On the Developer tab, in the Controls group, click Insert and then select the
ActiveX Check Box control.
16. Place the mouse pointer close to the top-left corner of cell E6. Before you click the
mouse, press the Alt key. Then click the mouse and drag the pointer just above and
to the left of the bottom-right corner of cell E6. Release the mouse button first and
then release the Alt key.
17. Click the Check Box control you just inserted into E6 to select it, if necessary. If the
six white circular resizing handles are not displayed around the borders of the
control, then click the Design Mode button on the Developer tab.
18. Click the Properties button.
a. For the Caption property, type Matte Finish?.
b. For the LinkedCell property, type [Link].X.
19. Turn off Design Mode and test the check box control.
20. Repeat previous instructions as appropriate to add the following controls:
a. An ActiveX Text Box control in E8 with a LinkedCell property of
[Link].X
b. An ActiveX List Box control in E11:E21, LinkedCell property is [Link].X
and the ListFillRange is [Link]
c. An ActiveX Option Button control in E23, LinkedCell property is
lnk.Option1.X and the Caption is Matte Finish
d. An ActiveX Option Button control in E25, LinkedCell property is
lnk.Option2.X and the Caption is Glossy Finish
e. An ActiveX Option Button control in E27, LinkedCell property is
lnk.Option3.X and the Caption is No Finish
21. Close the Properties window, turn off Design Mode, and test your controls.
22. On the Developer tab, click the Insert button. This time insert a Form control
Combo Box into cell I4.
23. Right-click the combo box control and select Format Control from the shortcut
menu. Select the Control tab.
10 de 12 14/04/2021, 14:32
OneNote [Link]
24. Set the Input range to [Link] and the Cell link to [Link].F and then
click OK.
25. Click any regular cell. If the pointer changes into a pointing finger when you mouse
over the control in cell I4, then you can use it.
26. Try typing Taupe into the Forms combo box in cell I4. Unlike the ActiveX combo
box, you can’t type into a Forms combo box.
27. Place a Form control check box in I6.
28. Right-click the check box and select Format Control.
29. On the Control tab, set the Cell link to [Link].F.
30. Click the Alt Text tab and change the alternative text to Matte Finish?. Click OK.
31. Click in cell H6 then press the right arrow key once. Then press Delete. This will
clear out the text in I6 so you can read the check box better.
32. Notice that changing the Alt Text in step 30 didn’t change the check box’s caption.
Right-click the check box control and select Edit Text to change the caption to
Matte Finish?.
33. Place a Form control list box across cells I8:I18. (Remember, if you press the Alt
key prior to starting your drag, the control will snap to the cell borders.)
34. Right-click the list box and select Format Control from the shortcut menu. Click
the Control tab and make the following entries:
a. Input range: [Link]
b. Cell link: [Link].F
35. Click OK and then select any cell in the worksheet. Test your Forms list box control.
36. Delete the text in cells I20, I22 and I24.
37. Place a Form control Option Button in cell I20 and edit the text to read Matte
Finish.
38. Place a Form control Option Button in cell I22 and edit the text to read Glossy
Finish.
39. Place a Form control Option Button in cell I24 and edit the text to read No Finish.
40. Right-click any of the Option Button controls and select Format Control. Click the
Control tab, set the Cell link to [Link].F, and then click OK. Your worksheet
should now look similar to Figure 2-26.
Take Note If you accidentally double-clicked any of the ActiveX controls in the process
of inserting them, depending on the type of control, Excel will automatically insert either
11 de 12 14/04/2021, 14:32
OneNote [Link]
a stub _Click Event Handler procedure or a stub _Change Event Handler procedure into
the code (class) module for the worksheet. You may have just closed the VBE or switched
back to Excel without really noticing that this happened. If you did this, then you’ll get a
message from Excel telling you that a VB project cannot be saved in a macro-free
workbook. Just click Yes to go ahead and save the workbook. The auto-generated event-
handler stub will automatically be discarded.
Note that in the case of option button controls, all three Form control option buttons
have the same linked cell and this linked cell contains the index of whichever option
button is selected. Compare that to the ActiveX option buttons where each option button
has its own linked cell and each linked cell toggles between TRUE and FALSE.
12 de 12 14/04/2021, 14:32