Week of
The Custom UI Editor is an easier way to modify the underlying XML code that makes up the Ribbon in an Office 2007 and newer documents.
Download this basic stats tool as a starting file: basic_stats_tool.xlsm
Save the spreadsheet file as a Macro Enabled Workbook (.xlsm
)
file before you write more code. Name your spreadsheet with your
network login followed by _l10.xlsm
. For example, if
your network login was barn4520
, then your lab file
should be named barn4520_l10.xlsm
. Save often.
Show the Developer Tab in Excel. In Excel 2010, click File / Options Customize Ribbon and check the option for Developer Tab.
Copy and paste this header into your code modules and fill it out:
Option Explicit ' ==== CP212 Windows Application Programming ===============+ ' Name: Your Name ' Student ID: ' Date: ' Program title: ' Description: '===========================================================+
When complete, raise your hand and show your task to the Lab Instructor or Marker to be marked. Your mark must be recorded before you leave the lab.
When finished upload your file to the Lab 10 Task Dropbox in MyLearingSpace. Saving the file to the Dropbox is simply a safety measure in the event there are problems with your grade later in the course.
To help choose icons (and the corresponding imageMSO value for the RibbonX code) use the Office 2007 Icon Gallery which is an Excel file that contains a custom tab displaying more than 3000 icons that can be used in your applications.
basic_stats_tool.xlsm
file you downloaded from the top of this lab.
imageMso
attribute to the one that you choose from the the Office 2007 Icon
Gallery. The place to make the changes are indicated below with
yellow highlighting. The RibbonX code has been spread across
different lines to make it more readable.
onAction
attribute from Callback
to the name of a subroutine that would be called when the button
on the ribbon is clicked. Call it displayUserForm.
FormCode
and paste in
the call back subroutine that you copied previously.
frmAverage.Show
.
On clicking the button you might receive an error message such as the one below:
In this case, the name of the onAction value (in this case, displayUserForm
)
doesn't match the name of the subroutine in the module. You can correct
this by changing the name of the subroutine in the VBE, or you can open
the Custom UI Editor again and fix the onAction
value.
You might also get this message, or it might appear after you fix the first problem:
This problem indicates your subroutine isn't taking the correct number
of arguments. You need to have used the callback subroutine generated by
the CustomUI Editor. If you already have your own subroutines written,
you'll need to make sure the sub takes an IRibbonControl
object as an argument like this:
Sub displayUserForm(control As IRibbonControl) frmAverage.Show End Sub
Now the subroutine executes by clicking the Ribbon button, but it can no longer be run from the worksheet in any way. It may look something like the image below.
That completes the lab, but if you want to continue to the next step, you would convert your application into an add-in that can be deployed to multiple users and is always available, much like the Solver add-in.
Note