Out: Nov 22nd
Due: Nov 29th, 12.01 pm in the drop box. (demo req’d on the 22nd)
Reading: Ch 13, pp261-280+ material on comboBox, checkbox, dropdown, menu
NEST 301 – Lab 8: Customizing the Ribbon
This exercise can be particularly difficult for the reason that there will be very little feedback if things go wrong. The instructions here follow the instructions in Chapter 13 of the text, with a slightly different instructions to make it easier to follow.
- Create a custom ribbon tab and demonstrate it when you are done in the Nov 16 lab.
- Step 1: Create a new macro enabled document and save it to your desktop. Insert the following macros. You will also find the 1st three stored in this document.
Sub RibbonLoader(ByVal ribbon As Office.IRibbonUI)
MsgBox "Ribbon Loaded"
End Sub
Sub MyButton(ByVal control As IRibbonControl)
MsgBox "Successful Button", vbInformation + vbOKOnly, control.ID
End Sub
Sub OtherButton(ByVal control As IRibbonControl)
MsgBox "Successful Menu Action"
End Sub
Sub SelectLanguage(ByVal control As IRibbonControl)
MsgBox control.ID, vbInformation, control.Tag
End Sub
Sub Beverage(ByVal control As IRibbonControl, currentState As Boolean)
MsgBox control.ID, vbInformation, currentState
End Sub
Sub SelectCourse(ByVal control As IRibbonControl, text As String)
MsgBox control.ID, vbInformation, text
End Sub
Save the file as yourName.docm and close it.
- Step 2: Select Start | Run | cmd to open a command window. You are going to have to switch the file several times between a .docm and a .zip file. Enter the commands to rename the file:
ren yourName.docm yourName.zip
ren yourName.zip yourName.doc
Observe that the icon switches back and forth . Use the up arrow key to cursor up between the commands. - Step 3: Convert the file to a zip file. Open the .zip file and the .rels file in the _rels directory. Drag the .rels file to the desktop , right click on it and select Wordpad to edit the file. Note that you cannot edit the .rels file while it is inside the zip file, only when it is on its own.
You will note a series of 4 relationship tags in between <Relationships> and </Relationships> Add a 5th tag by copying the following exactly!!! You can cut and paste from these instructions but retype the quotations in Wordpad – Word converts them to a different symbol and you don’t want this to be a problem.
<Relationship Id="MyRibbonID" Type=" Target="MyRibbon.xml"/> - Step 4: Download the file MyRibbon.xml from the course web site. A listing of the file appears on the last page. Print it out so that you can study it, mark it up and go over it while figuring out how to complete these exercises.
- Step 5: Repackaging the zip file:
- Copy the modified .rels file back in the _rel directory of the zip file
- Copy the modified file MyRibbon.xml to the top level of the zip file
- Rename the zip file back to a docm file
- Open the file. A mesage box “Ribbon Loaded” should appear. This comes from the RibbonLoader method that you entered in step 1 You should see a tab “My Tab” next to the developer tab. Select it and the buttons and menu should appear. Try out each button, checkbox and menu item.
- Review the file Ribbon.xml and the macro functions and write your observations. (6 total)
- Create a chart showing which Macro is associated with which IDs in the Ribbon.xml file (2 marks)
Macro / Ribbon ID
Ribbon Loader
MyButton
OtherButton
SelectLanguage
Beverage
SelectCourse
- What error message do you get if you remove one of the macros and then click on the associated ribbon elements. (Do NOT modify Ribbon.xml, just rename one of the macros) (1 mark)
- Select and then deselect the Coffee and Tea checkboxes. Explain how the macro associated with these check boxes knows whether or not the box is selected. (1 mark)
- You’ll notice that there is no macro associated with Donut or Muffin. Note how the other ribbon items are associated with macros and write a macro that gets run when you select either one. The macro should report which of Donut or Muffin gets selected. (2 marks)
- Download the file Office2007IconsGallery.xlsx from the course web site and open it. Select the Developer tab and you will notices a number of Galleries. Under each gallery is a large selection of icons. If you hold the mouse over one of the icons a name for the icon will appear. (10 marks)
The following customizations are designed to ensure that everyone develops a custom ribbon individually. No two ribbons will look or behave exactly alike. Before each step - Convert the file to a zip file
- Modify MyRibbon.xml and move the altered file into the zip file
- Convert the file back to a .docm file.
- Test that the change worked
- If the change did not work carefully examine your modified MyRibbon.xml and look for spelling errors, case sensitivity, missing quotes or other characters. If necessary revert to an earlier version of MyRibbon.xml and try a different set of changes.
- Review Ribbon.xml. Each tag can have an attribute: imageMso=”iconName”, and several do. Modify the imageMso tags for each of the languages in the Menu so that each language has a different icon where the icon name is taken from the gallery. (1)
- Add a new language to the language menu. Note that the id associated with the item must be unique. (1)
- Add a screentip and a supertip to the Muffin checkbox. Check one of the buttons to see how it’s done. (1)
- Create a new group. Put a new button in the group with its own imageMso. The id of the button should be your name. Have the button run its own macro and add the macro. (3)
- Create a new Tab with its own id and label. (1)
- The instructions on pp284-285 show you how to create a dropDown list. Create a new group and put a dropdown list in it. Associate the items in the dropDown with the same macro as the Combo and test. (3)
File MyRibbon.xml
<customUI xmlns=" onLoad="ribbonLoader"
<ribbon startFromScratch="false">
<tabs>
<tab id="CustomTab" label="My Tab" keytip="Z">
<group id="CustomGroup" label="My Group">
<button id="CustomButton1"
imageMso="HappyFace"
label="Hello World!"
size="large"
onAction="Module1.MyButton"
screentip="Hello World"
supertip="Displays the canonical Hello World! message."
keytip="M" />
<button id="CustomButton2"
imageMso="EquationOptions"
label="Nice Day"
size="large"
onAction="Module1.OtherButton"
screentip="Another Button"
supertip="Does something else"
keytip="N" />
</group>
<group id="CustomGroup2" label="My Group2">
<button id="CustomButton3"
imageMso="EquationOptions"
label="Nice Day"
size="large"
onAction="Module1.OtherButton"
screentip="Another Button"
supertip="Does something else"
keytip="P" />
</group>
<group id="MenuDemo" label="Menu Demo" >
<menu id="Menu1" label="Languages">
<button id="Lang1" imageMso="FileSave" label="English"
onAction="Module1.SelectLanguage" />
<button id="Lang2" imageMso="FileSave" label="French"
onAction="Module1.SelectLanguage" />
<button id="Lang3" imageMso="FileSave" label="Spanish"
onAction="Module1.SelectLanguage" />
<button id="Lang4" imageMso="FileSave" label="Punjabi"
onAction="Module1.SelectLanguage"/>
</menu>
</group>
<group id="CheckBoxDemo" label="CheckBox Demo" >
<checkBox id="Cofee" label="Coffee" onAction="Module1.Beverage" />
<checkBox id="Tea" label="Tea" onAction="Module1.Beverage" />
<checkBox id="Snack1" label="Muffin" onAction="Module1.Snack" />
<checkBox id="Snack2" label="Donut" onAction="Module1.Snack" />
</group>
<group id="ComboDemo" label="Combo Demo" >
<comboBox id="Combo1" label="Courses" sizeString="mmmmmmmmmmm"
onChange="Module1.SelectCourse" >
<item id="NEST301" label="Automatic Office Applications" />
<item id="NEST303" label="Networking Technologies" />
<item id="NEST304" label="Unix Operations" />
<item id="NEST305" label="Server Operating Systems" />
<item id="NEST307" label="Customer Support" />
</comboBox>
</group>
</tab>
</tabs>
</ribbon>
</customUI>