View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_7_] Peter T[_7_] is offline
external usenet poster
 
Posts: 162
Default Ribbons depending on ActiveSheet


"GS" wrote in message
Claus' link had some interesting stuff I hadn't seen yet from RdB. Looks
like you're in luck with your intent!<g

I looked at Ron's enable/disable samples some time ago looking to replace
my context-sensitive scheme for toolbars going with custom tabs in a
dictator app config. I abondoned that approach because it uses the 'Tag'
property of controls/groups. I'm already using Tag/Parameter props and
didn't want to disturb my methodology. I'm going to revisit this with a
new approach: some of my Tag/Parameter values are delimited value
sets/pairs. I believe I can make this work for all where enable/disable
will be able to occur using only the first element in the Tag string with
a wildcard "*" as exampled in Ron's demo. This, of course, means a rewrite
of code but seems worth it in the long run...


Garry,
Not sure which of Ron's examples you're looking at but typically you'd use
the tag (or id) property in the same callback that's called by multiple
controls. So when the same callback is called successively you can look at
the property to see if you want to change the return value. I assume the "*"
is being used with Like to do the same action to each control, though could
achieve the same objective in different ways.

Charlotte,
You didn't say which method you're using to hide the Ribbon (with things
like this it's better to be explain because it leads to different answers)
but there are basically two approaches.

1. Use StartFromScratch, and rebuild the Ribbon identically using your own
custom tabs & controls, or rather the built-in mso, together with callbacks
for the tabs to show/hide if/when required. This is typically used in
Dictator style apps where you want to hide everything including the QAT and
Office/Backstage menus. From memory Ron has excellent examples using
StartFromScratch so no need to add any more detail here.

2. For the builtin controls you want to show/hide include the "getVisible"
action in the xml, which for each can be to the same callback.
Also in the xml include the Ribbon's "onLoad" so you can set a reference to
it and do "Invalidate". Not sure if Ron includes examples not using
StartFromScratch, so a simplified xml might look like this

<customUI
xmlns = "http://schemas.microsoft.com/office/2006/01/customui"
onLoad="rxRibbon_onLoad"
<ribbon startFromScratch="false"
<tabs
<tab
idMso = "TabHome"
Tag = "TabHome"
getVisible="Tab_getVisible"/
<tab
idMso = "TabInsert"
Tag = "TabInsert"
getVisible="Tab_getVisible"/
</tabs
</ribbon
</customUI

the vba

Public grxRibbon As IRibbonUI
Public gbHide As Boolean

Sub rxRibbon_onLoad(ribbon As IRibbonUI)
Set grxRibbon = ribbon
' note while developing it's easy to lose the grxRibbon ref, but there's a
well known fix to restore it
End Sub

Sub Tab_getVisible(control As IRibbonControl, ByRef returnedVal)
' Debug.Print control.ID ' this might be useful
returnedVal = Not gbHide
End Sub

Sub test()
gbHide = Not gbHide
grxRibbon.Invalidate ' clears the cache and triggers the getVisible
callback
End Sub

Save/close an xlsm with the code, and add the above xml with the "Custom UI
Editor". Open the xlsm and manually run Sub test() to goggle visibility of
the Home & Insert tabs. Add similar xml for the other builtin tabs, these
are the main ones
TabHome
TabInsert
TabPageLayoutExcel
TabFormulas
TabData
TabReview
TabView
TabDeveloper
TabAddIns

could also include the contextural tabs

There are advantages & disadvantages to using StartFromScratch, or depending
on how much you want to hide (eg Office/BackStage QAT, custom ribbon stuff
from other addins) StartFromScratch might be the only way.

Regards,
Peter T