web 2.0


How to: Office 2007 CustomUI – getVisible attribute

When working with the Office 2007 CustomUI, you may want to toggle visibility of certain tabs or groups, for example. You accomplish this by using the getVisible attribute of the XML UI code and then wrapping it with a callback to handle the visibility.

In this article, I show you how to toggle the Office 2007 CustomUI visibility for a whole group and a group depending on the active worksheet (I will use Excel as the basis for this example). To begin with, we need to add the XML code to our XLSM file:

<customUI xmlns=
"http://schemas.microsoft.com/office/2006/01/customui" onLoad="rx_onLoad">
 <
ribbon
>
  <
tabs
>
   <
tab idMso="TabHome" label="My Home Tab" getVisible="rx_getVisibleTab"
>
    <
group idMso="GroupClipboard" getVisible="rx_getVisibleGroupClipboard"
/>
   </
tab
>
  </
tabs
>
 </
ribbon>

</customUI>

Notice that we have the following callbacks to generate:

·         rx_onLoad

·         rx_getVisibleTab

·         rx_getVisibleGroupClipboard


The first callback handles the setting of our ribbon object and the default values for the tab and group visibility. The second and third callbacks simply pick up the visibility boolean value and return it as the object’s visibility status (either the entire Home tab or the clipboard group or both).

Next, you should add a module where the following code should be added:

Option Explicit

Public rxMyRibbon                                       As IRibbonUI
Public rxblnTabHomeVisible                              As Boolean
Public rxblnGroupClipboardVisible                       As Boolean

Sub rx_onLoad(ribbon As IRibbonUI)
    Set rxMyRibbon = ribbon
    rxblnTabHomeVisible = True
    rxblnGroupClipboardVisible = True
End Sub

'Callback for TabHome getVisible
Sub rx_getVisibleTab(control As IRibbonControl, ByRef returnedVal)
    returnedVal = rxblnTabHomeVisible
End Sub

'Callback for GroupClipboard getVisible
Sub rx_getVisibleGroupClipboard(control As IRibbonControl, ByRef returnedVal)
    returnedVal = rxblnGroupClipboardVisible
End Sub


Finally, the visibility will depend on which sheet is active, thus in the code module for ThisWorkbook, you should add the following code:

Option Explicit
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Dim shIndex                    As Integer
   
    shIndex = Sh.Index
   
    Select Case shIndex
        Case 2
            rxblnTabHomeVisible = True
            rxblnGroupClipboardVisible = False
        Case 3
            rxblnTabHomeVisible = False
        Case Else
            rxblnTabHomeVisible = True
            rxblnGroupClipboardVisible = True
    End Select
   
    rxMyRibbon.Invalidate
End Sub


In the above scenario, if the active sheet has an index equal 2 (two); then the tab should be visible but not the clipboard group. When the index is 3 (three) then the whole tab should be invisible. Otherwise, all should be visible.

You can download the sample file here:
www.msofficegurus.com/uploads/getVisible.xlsm.

For further information on the Ribbon, you can this book:

Tags: , , ,

Microsoft Excel - VBA | Microsoft Office | Microsoft Office - VBA | Ribbon

Excel 2007: Pulsating (flashing) Office Button

In Office 2007, Microsoft introduced what is widely known as the "Office Button". This is a button that functions in the same way as the old "File" menu, which gives you tools to work with the file such as Save As, Print, etc.

Have you e
ver wondered why the Microsoft Office Button flashes? Or how to make it flash again?

The first thing to know is that the Button flashes for discoverability reasons, that is, it flashes with the implicit and silent message: "Hey, I am here! Click me!". Once you have "discovered" the Office Button, it will stop flashing in all of the Office applications.

Here's a cool trick to get the Office Button to flash again by tweaking the Windows Registry. Have fun!


Tags: , , ,

Microsoft Office | Ribbon

Office 2007: Customizing the Office 2007 Ribbon

I’ve been working with Office and the new User Interface (UI) since the first beta was available to me. There is a common complaint about “how difficult” it is to get around the Ribbon, that it is less productive, that you need more clicks to get to a command, yadayadayada.

Is the Ribbon larger? Does it take more screen space? Well, get that measuring tape out of your toolbox and measure it by yourself and be surprised after comparing it to the old toolbars. Are the commands more difficult to find? Have a go in creating and modifying a chart and let me know.

I don’t have the statistics for all those who complain about the new UI, but from those who I have heard the complaints they all have one thing in common: they have used Office for a loooooooong time and had way too many customizations for which they will die before giving them up. As for the average user, it probably does not matter that much as they were using a fraction of Office resources and had little customizations of their own (I am saying this one without the stats to back it up, just guesswork).

But I am a guy who loves change. I see change as challenge, except for the middle part (“lle”), and the new UI represents just that: a challenge. And challenges are opportunities. It keeps us on the ball, active, and shrugs off any possible brain rheumatism we may be prone to.

This is how the RibbonX book came to life and I am happy we have had good feedback on it. It is a pity we left out Visual Studio, but at the time we thought it was not mature enough to justify a chapter on it. After VS 2008, I am convinced things will have changed drastically for the better and, the publishers willing; we will have a second edition which will be much richer in content.

If you have any queries or want to discuss things further, drop me a line.

As Teresa would say: life is full of opportunities, celebrate them all!

Tags: , , ,

Microsoft Office | Ribbon

Customizing the Ribbon: startFromScratch and Tab visibility

If you start from scratch, then using the getVisible attribute to show/hide a tab will not work, since you'd have to rebuild the functionalities for the elements. However, an option would be to simply start all tabs hidden and then show/hide as you go along, this would avoid the frustrating of having to rebuild each tab using XML to work with them.

Remember that working with startFromScratch does not stop the user from hitting shortcut keys to access certain functionalities (at least for now), so it is pretty much pointless to start from scratch except for the fact you’d have all the tabs and certain commands hidden from the outset. Here’s an option to work with an Excel file. Use the following XML to built your own custom tab:

<customUI
  xmlns="http://schemas.microsoft.com/office/2006/01/customui"
  onLoad="rxRibbon_onLoad">

  <ribbon
   startFromScratch="false">
   <tabs>
    <tab
     idMso="TabHome"
     getVisible="TabHome_getVisible"/>
   <tab
     id="rxTab0"
     label="My Custom Tab">

     <group
      id="rxGrp0"
      label="My Custom Group">

      <toggleButton
       id="rxtglBtn0" getLabel="rxtglBtn0_getLabel"
       imageMso="HappyFace"
       size="large"
       onAction="rxtglBtn0_Click" />
     </group>
    </tab>
   </tabs>
  </ribbon>
</customUI>

You can then write some code in your workbook as follows to control visibility (place code in a standard module):

 

Public rx_oRibbon             As IRibbonUI
Public blnGetLabelState       As Boolean
Public blnHomeTabVisibility   As Boolean

Sub rxRibbon_onLoad(ribbon As IRibbonUI)
  Set rx_oRibbon = ribbon
  blnGetLabelState = False
  blnHomeTabVisibility = False
End Sub

Sub rxtglBtn0_getLabel(control As IRibbonControl, ByRef returnedVal)
  Select Case blnGetLabelState
    Case True
      returnedVal = "Hide 'Home Tab'"
    Case False
      returnedVal = "Show 'Home Tab'"
  End Select
End Sub

Sub TabHome_getVisible(control As IRibbonControl, ByRef returnedVal)
  returnedVal = (blnGetLabelState)
End Sub

Sub rxtglBtn0_Click(control As IRibbonControl, pressed As Boolean)
  blnGetLabelState = pressed
  rx_oRibbon.Invalidate
End Sub

Tags: , , , , ,

Microsoft Office | Microsoft Office - VBA | Ribbon