X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
   Closed TopicStart new topic
> How to get started with the Office 2007 Ribbon/Menu!    
post May 25 2007, 01:56 PM

UtterAccess VIP
Posts: 31,413
Joined: 23-September 04
From: NC, USA

This is a quick tutorial on how to get started with customizing the new Ribbon in Microsoft® Office 2007. I will write and test this using Microsoft® Access 2007 but I am sure it can be applied to other Office 2007 programs similarly.

The best approach to customizing the new user interface is XML. This might be somewhat intimidating if you have never worked with Extensible Markup Language before but using this tutorial you should be able to get a head start and take it wherever you want afterwards.

First Step (creating Ribbon table):

Create a Ribbon table which will hold our XML and a unique name assigned to the XML code. Name this table USysRibbons. This ensures that the table will be hidden in the Navigation Pane unless you have the “Show System Objects” option checked under the Navigation Options dialog.
o open the Navigation Options dialog right click on the Navigation Pane’s
selection bar at the top and select Navigation Options…or open the Access
Options dialog (at the bottom right of the Office menu pull down behind the big
round Office button in the top left corner of the Access shell). Than choose
Current Database and press the Navigation Options… button displayed there.

The table layout could be as follows:

  • RibbonName (Text, PK)
  • RibbonXML (Memo)

Second Step (defining new Ribbon record with name and XML):

Open the table in datasheet view...we are ready to add some XML. The majority of questions I have seen deal with the disabling/hiding of certain commands or the Ribbon all together. So we will have a look at that. Add a new record in your table with a RibbonName value of CommandsDisabled and the following associated XML in the RibbonXML field:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
             <command idMso="FileNewDatabase" enabled="false"/>
             <command idMso="FileCloseDatabase" enabled="false"/>
             <command idMso="ApplicationOptionsDialog" enabled="false"/>
             <command idMso="FileExit" enabled="false"/>

Third Step (applying/testing the customization):

For the Ribbon to be recognized you need to close and reopen the application. So close the table/application and reopen it. After that go to the Current Database tab of the Access Options dialog (described earlier). Under Ribbon and Toolbar Options select CommandsDisabled in the Ribbon Name drop down. After pressing OK Access should notify you that you need to close and reopen the application for the change to take effect. So close and reopen the application. Afterwards go back to the round Office button in the top left corner and check the New, Close Database, Access Options, and Exit Access commands. They should all be grayed out and inaccessible.

Congratulations…you have just customized the new user interface. The shift bypass key affects the user customization similarly to other options you might have used before. So to temporarily return to the design state you can just close the application and reopen it while holding down the shift key.

Fourth Step (hiding/disabling the Ribbon):

Again open the USysRibbons table and add a new record with a RibbonName value of HideRibbon and the following XML for RibbonXML:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
      <ribbon startFromScratch="true">

Setting the startFromScratch attribute to true will completely hide the Ribbon, remove certain commands from the Office pull down as well as the quick launch bar if you do not specify any further actions.

HAs described in step three close and reopen the application and set the new Ribbon Name in the Access Options dialog. Then close and reopen the application for the XML to take effect.

Fifth Step (be creative and take it form here):

This short tutorial should have helped you get started. The Ribbon exposes many cool user interface features which have not been possible up till now. You can display galleries, drop downs, split buttons…and construct a really rich and friendly interface for your users. As a little hint I will show you one more step to creating a custom Ribbon button which executes a specified action when clicked. Add the following XML to a new record in your Ribbon table:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
      <ribbon startFromScratch="true">
                <tab id="tab1" label="Your Custom Tab">
                      <group id="group1" label="Your Custom Group">
                               <button id="SampleButton" label="Click Me" onAction="OnButtonPress"/>

Ribbon commands act through the help of callbacks which are little subs you write in VBA code. In this example the onAction of the SampleButton will correspond to a callback named OnButtonPress. After closing your Ribbon table create a new module and paste the following code in it:
Public objRibbon As IRibbonUI
Public Sub OnRibbonLoad(objRib As IRibbonUI)
    Set objRibbon = objRib
End Sub
[color="green"]'our callback for the SampleButton[/color]
Public Sub OnButtonPress(ctl As IRibbonControl)
    If (ctl.ID = "SampleButton") Then
        MsgBox ("You have just executed the OnButtonPress callback when clicking" _
                & vbCrLf & "the Ribbon SampleButton!")
    End If
End Sub

Save the module as whatever you want as long as it doesn’t have a name of a procedure/function it houses. Follow the instructions in step three to assign this new Ribbon XML to the application. After closing and reopening the application you should see one tab named My Tab holding one group named My Group which houses one button named Click Me. If you press the button you should receive the message box we defined in the callback procedure.

Now it is up to you to keep going and impress us. Feel free to post screenshots or sample applications of your accomplishments here in the User Interface Forum at UtterAccess.

For some more information on specific commands, features and functions you might find the following articles helpful:

By the way...if you are using an existing MDB file with custom menu/command bars and you want to continue to only display those in Access 2007 than follow these detailed instructions:

Another quick trick to manipulate the Access interface is to change your application's ACCDB extension to ACCDR. This results in a locked version of your application which effects the user interface as well.
Go to the top of the page

Custom Search
RSSSearch   Top   Lo-Fi    19th October 2018 - 07:08 AM