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