Professional Documents
Culture Documents
DynamicToolbar PDF
DynamicToolbar PDF
B e y o n d E x c el
PROJECTS
DYNAMIC TOOLBAR
Dynamic Toolbar
B e y o n d E x c el
Dynamic Toolbar
B e y o n d E x c el
Table of Contents
Why Read This? .................................................................................................................................................................................... 1
Which is best for me? ....................................................................................................................................................................... 1
Installing the Demo .............................................................................................................................................................................. 2
Dynamic Toolbar Introductory Video ............................................................................................................................................ 2
Requirements ................................................................................................................................................................................... 2
Installing ........................................................................................................................................................................................... 2
Running ............................................................................................................................................................................................ 2
Adding Dynamic Toolbar to Workbooks ............................................................................................................................................... 3
Configuring Dynamic Toolbar ............................................................................................................................................................... 4
TDT Toolbar Definition Table ..................................................................................................................................................... 5
Coding .................................................................................................................................................................................................. 7
Invoking Dynamic Toolbar with the Add-In ....................................................................................................................................... 7
Invoking Dynamic Toolbar without the Add-in .................................................................................................................................. 8
Coding Callbacks ........................................................................................................................................................................... 9
Examples: ..................................................................................................................................................................................... 9
Reading and Setting Control Values ................................................................................................................................................ 10
Creating Icons..................................................................................................................................................................................... 11
Technical Documentation ................................................................................................................................................................... 16
Introduction ................................................................................................................................................................................... 16
Components ................................................................................................................................................................................... 16
Forms ......................................................................................................................................................................................... 16
Modules ..................................................................................................................................................................................... 16
Classes (Event Handlers) ............................................................................................................................................................. 16
Dynamic Toolbar
B e y o n d E x c el
Beginners
Use this add-in to easily create
Ribbon-like interfaces for XL workbooks.
Developers
Learn about dynamically created
UserForms, Controls, Events, and Classes.
What is the Dynamic Toolbar?
When we need an easy and elegant
way for users to access macros/routines,
we have a few options:
1) Paste Buttons on Worksheets
From Developer tab find Controls
group and use Insert to paste a controls
to the worksheet, add text, set some
properties and assign a macro. Its easy
but takes up worksheet space and limits
our user interface to one worksheet or
we must replicate all controls to other
worksheets. It looks unprofessional.
5) Dynamic Toolbar
Dynamic
Toolbar
adds
a
customizable
floating
Ribbon-like
interface for XL applications like
PapaGantts and KitchenDesigns toolbars
shown above. Dynamic Toolbar is by far
the easiest to learn and use because we
configure it using normal Excel tables
instead of XML or VBA; and because it
requires only a handful of properties. It
also shares Ribbon Commanders ability
to change the toolbar while our app is
running.
Dynamic Toolbar cannot do all the
MS Office Ribbon does, but it does
enough; is instantly recognizable so users
know how to use it; and can be
assembled in a fraction of the time and
effort. It also happens to be a great way
to learn about adding, placing and
manipulating all kinds of controls on a
UserForm through VBA.
3.
Page 1
Dynamic Toolbar
B e y o n d E x c el
Dynamic Toolbar
Dynamic Toolbar Introductory Video
http://youtu.be/hNuiTlLmGWE
Requirements
Installing
Running
1.
2.
3.
4.
1.
2.
3.
4.
5.
Download DynamicToolbar.Zip
Open your Downloads folder, NOT
the zip file.
Right click DynamicToolBar.Zip and
select Extract All.
Make sure Show extracted files when
complete is checked.
Make note of the extracted folders
path.
Page 2
Dynamic Toolbar
B e y o n d E x c el
1.
2.
3.
Create or copy icons into your projects directory (if using Button or Command control types).
Reference: Creating Icons
4.
Add the Dynamic Toolbar add-in, OR copy the three Dynamic Toolbar modules to your project and code to display the
Dynamic Toolbar when your workbook opens and/or when the user presses CTRL-T
Reference: Invoking Dynamic Toolbar with the Add-In
Or
Invoking Dynamic Toolbar without the Add-in
5.
Record or write macros/routines for each control to run and name them exactly as your entered in TDTs Call Back column
6.
Make sure the routines have the appropriate parameters for the control type.
Reference: Coding Callbacks
When these six steps are completed, Dynamic Toolbar is ready for your project.
Page 3
B e y o n d E x c el
Dynamic Toolbar
Button
TextBox
DropBox
CheckBox
Group
Configuring
Dynamic
Toolbar
involves making entries in an XL table
that I call the TDT (Toolbar Definition
Table). Below is the TDT used to create
the above Dynamic Toolbar.
TDT
Toolbar Definition Table
Tab
Group
PapaGantt Identification
PapaGantt Identification
PapaGantt Database
PapaGantt Database
PapaGantt Database
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
PapaGantt
Button
Button
Button
Button
Button
Button
Button
DropDown
DropDown
CheckBox
CheckBox
CheckBox
Button
Button
Button
Actions
Actions
Actions
Actions
Actions
Actions
Actions
Settings
Settings
Options
Options
Options
About
About
About
modGantt.ClrTbl
modGantt.Indent
modGantt.Outdent
modGantt.CrtWBS
modGantt.ClcTsk
modGantt.CrtCht
modGantt.PrtCht
modGantt.ChgLvl
modGantt.ChgInt
modGantt.DspLin
modGantt.CsrCtl
modGantt.DspIM
modGantt.DspAbt
modGantt.DspPDF
modGantt.DspBXL
Icons\Clear48.gif
Icons\Indent48.gif
Icons\Outdent48.gif
Icons\WBS48.gif
Icons\Recalc48.gif
Icons\Draw48.gif
Icons\Print48.gif
*All,0,1,2,3,4,5,6,7,8,9
Years,Quarters,Months,Weeks,Days,Hours,30,15,5,1
Setting
Project
1
*All
Weeks
TRUE
TRUE
TRUE
Icons\About48.gif
Icons\Acrobat48.gif
Icons\BXL48.gif
Page 4
B e y o n d E x c el
Dynamic Toolbar
TDT Toolbar Definition Table
The TDT has only seven columns; which means it takes no more, and sometimes fewer than seven entries to define a Toolbar
control. Here is what each column is:
Column/Field
Tab
Description
This determines which Groups and Controls display in Dynamic Toolbar. Unlike MS
Offices Ribbon, Dynamic Toolbar currently displays only one tab at a time, but we
can define multiple tabs in the same TDT and change which tab to display in
Dynamic Toolbar at any time.
ATTENTION ENTERPRISING DEVELOPERS!
Try adding a MultiPage control to Dynamic ToolBar to enable multiple tabs.
Group
This determines which Controls appear in a Group. Grouping controls can add order
to Dynamic Toolbar and improve its appearance. Group captions appears at their
bottom.
Control
Command
DropBox
CheckBox
TextBox
Use text boxes for entering names, captions, or other free form
text or properties.
All controls have captions. Enter one, two, or three words to explain what the
control does.
Call Back
Page 5
Dynamic Toolbar
Column/Field
Values
Description
This column/field is dependent on what is in the control column/field. For:
Setting
B e y o n d E x c el
Buttons and Commands this is the image file (with path if not in the same
directory as the workbook).
ComboBoxes this contains values to list.
CheckBoxes and TextBoxes this does not apply
ComboBoxes, CheckBoxes and TextBoxes get their initial values from here. They
also set this value when they change. Our routines can get the Dynamic Toolbar
controls current values from here.
Page 6
Dynamic Toolbar
B e y o n d E x c el
Coding
Invoking Dynamic Toolbar with the Add-In
The purpose of Dynamic Toolbar is to run macros/VBA routines and there is a little VBA required to set up the add-in.
NOTE!
Running AddInDemo.xlsm installed the Dynamic Toolbar add-in on your PC. With Dynamic Toolbar installed we
can load it into our projects manually using the DEVELOPER tab, Add-Ins button, checking Dynamictoolbar in the
Add-Ins dialog and then clicking OK
Add the above code to your projects ThisWorkbook module to load the
DynamicToolbar add-in when our workbook opens. The code also contains one
way to launch the toolbar using the keyboard shortcut Shift-Ctrl-T (We can
choose a different key if we want to preserve the Table Totals keyboard
shortcut).
NOTE! Change the Tab. The above code launches tab PapaGantt. Change PapaGantt to whatever your tabs name is.
NOTE! Run "'DynamicToolbar.xlam'!Display" is an example of calling an external VBA routine. Even though
add-ins are loaded with a host workbook, add-ins are not part of the host workbook. They are external to the
host workbook. To call external routines we must use Application.Run or, more concisely, the Run method.
NOTE! Tables - VBA knows XLs tables as ListObjects. When we create a table in XL it receives a name that can be
found in XLs Name Manager. I use TDT as the Toolbar Definition Tables name. We can use XLs Names in
VBA using VBAs Evaluate method. Brackets around Names are shorthand for VBAs Evaluate method. Thus,
[TDT] is shorthand for Evaluate(TDT). VBAs Range object also evaluates names like this: Range(TDT)
so [TDT] is also shorthand for Range(TDT); thus, [TDT] evaluates to the tables Range, not its ListObject.
If a Range is part of a table, we can get the ListObject from the Range like this: Range(TDT).ListObject,
or more concisely [TDT].ListObject
2014 Craig Hatmaker
Page 7
Dynamic Toolbar
B e y o n d E x c el
modGeneral
clsDynTB
We can drag these three modules from DynamicToolbar.xlam into our project and
not bother with using an add-in. This may make project distribution easier and coding
Dynamic Toolbar invoking routines simpler.
Page 8
B e y o n d E x c el
Dynamic Toolbar
Coding Callbacks
A callback is just another term used in the Microsoft ribbon community for a macro (or routine) assigned to a ribbon control.
Dynamic Toolbar is not a ribbon. It just looks and acts like a ribbon. I am leveraging ribbon terms to prepare readers who go on to
customizing the ribbon. While callbacks are simply macros/routines assigned to a ribbon control, different ribbon control types
require different callback stubs (macro/routine templates). The table below provides examples.
Control
Buttons,
Commands
Description
Have no required parameters.
ComboBoxes
CheckBoxes
TextBoxes
End Sub
End Sub
End Sub
NOTE!
All callbacks can contain optional parameters, and all parameters, including the first, can be declared Optional.
Dynamic Toolbar will only use the required parameter listed in the table above.
NOTE!
Controls are not required to have a callback at all. Setting an option, for example, might not need an immediate
reaction and but its setting could be required by some operation not yet started.
Examples:
Scenario
Button or Command
Display worksheet Sales. The Buttons callback is DisplayChart.
CheckBox
Turn EnableEvents on or off. The CheckBoxs callback is SetEvents.
ComboBox
Set font size. The ComboBoxs callback is FontSize.
Code
Public Sub DisplayChart()
Worksheets(Sales).Activate
End Sub
Public Sub SetEvents(byVal bOnOff as Boolean)
Application.EnableEvents = bOnOff
End Sub
Page 9
B e y o n d E x c el
Dynamic Toolbar
Reading and Setting Control Values
If a routine needs to know which ComboBox option is selected, or if a CheckBox is checked, we can provide our routines the
current setting from the TDTs Setting column. We can also examine frmDynTBs controls directly. Getting values from frmDynTBs
controls requires three pieces of information:
Question
Is frmDynTB displayed?
Which tab Is frmDynTB displaying?
Which control is Project Name textbox?
Code Solution
If frmDynTB.Visible then
IF frmDynTB.Caption = sMyTabName then
Dim lRow
Dim oMyControl
as Long
as Object
NOTE!
frmDynTBs control names are their TDT row formatted to three positions with leading zeroes. Ex: 001
Page 10
Dynamic Toolbar
B e y o n d E x c el
Creating Icons
Creating icons is easy. The easiest way is to simply copy an image and reduce it to the size we need. Here is an example.
Imagine we just recorded a report macro and need a Report icon so users can click it on the Dynamic Toolbar and create the report
from freshly downloaded data. Where can we get a Report icon?
Instructions
Open browser and navigate to Google
Screen Shots
Page 11
Dynamic Toolbar
Instructions
Chances are this screen will not provide
what we need so click Images.
B e y o n d E x c el
Screen Shots
Page 12
Dynamic Toolbar
Instructions
Right click on the image and select Copy
Image.
B e y o n d E x c el
Screen Shots
Page 13
Dynamic Toolbar
Instructions
Make sure Pixels is clicked and then set
Horizontal to 50 pixels. If Maintain
aspect ratio is checked (the default) we
do not need to set the Vertical to 50.
B e y o n d E x c el
Screen Shots
Click Crop
Page 14
Dynamic Toolbar
Instructions
Click the file dropdown and then select
Save As and one of these picture
formats: JPEG, BMP, or GIF (I prefer
JPEG).
B e y o n d E x c el
Screen Shots
Page 15
B e y o n d E x c el
Dynamic Toolbar
Technical Documentation
Introduction
The two main components
interest are frmDynTB and clsDynTB.
of
Components
Forms
Form
frmDynTB
This UserForm starts out with no controls.
Routine AddControls adds all controls.
Routines
AddControls
Description
Creates all controls for TDT rows matching a Tab name.
Display
Fill
FindGridCell
Routine
DspErrMsg
Description
This is a stripped down version of my normal DspErrMsg.
For more information about how I prefer to handle errors
see: Beyond Excel: Error Handling.
Color
Display
SetControl
Method/Property
<Control>_MouseMove
Description
See Glow
<Control>_Click
See Change
Modules
Module
modGeneral
General routines
<Control>_Change
Setup
Change
Page 16
Dynamic Toolbar
Class
B e y o n d E x c el
Method/Property
QualifyCallBack
Description
Makes sure routines are called from the appropriate
project.
Glow
ResetColor
Page 17