UtterAccess.com
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!    
 
   
freakazeud
post May 25 2007, 01:56 PM
Post#1


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


Hi,
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.
CODE
  
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:

USysRibbons:
  • 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:
CODE
  
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
      <commands>
             <command idMso="FileNewDatabase" enabled="false"/>
             <command idMso="FileCloseDatabase" enabled="false"/>
             <command idMso="ApplicationOptionsDialog" enabled="false"/>
             <command idMso="FileExit" enabled="false"/>
      </commands>
</customUI>

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:
CODE
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
      <ribbon startFromScratch="true">
      </ribbon>
</customUI>

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:
CODE
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
      <ribbon startFromScratch="true">
              <tabs>
                <tab id="tab1" label="Your Custom Tab">
                      <group id="group1" label="Your Custom Group">
                               <button id="SampleButton" label="Click Me" onAction="OnButtonPress"/>
                      </group>
                </tab>
              </tabs>
        </ribbon>
</customUI>

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:
CODE
[color="green"]'declaration[/color]
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:
http://msdn2.microsoft.com/en-us/library/bb187398.aspx
http://www.microsoft.com/downloads/details...;displaylang=en
http://msdn2.microsoft.com/en-us/library/aa338202.aspx
http://msdn2.microsoft.com/en-us/library/aa338199.aspx
http://msdn2.microsoft.com/en-us/library/aa722523.aspx
http://msdn2.microsoft.com/en-us/library/bb425845.aspx

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:
http://msdn2.microsoft.com/en-us/library/bb258174.aspx

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.
thanks.gif
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    14th December 2017 - 11:25 PM