Reputation: 3316
How can I hide and show all the standard Excel ribbon tabs using VBA (not XML). I do not want to hide the whole ribbon (as is asked here: VBA minimize ribbon in Excel) just the tabs. I know how to use startFromScratch using XML so please do not suggest that or other XML solutions.
So far I have done an extensive Google search and looked at:
What I am saying is I have already done an extensive search and tried many things without getting a result.
Upvotes: 11
Views: 47683
Reputation: 29
Try:
For cb = 1 To Application.CommandBars().Count
With Application.CommandBars(cb)
If .BuiltIn And .Visible Then
.Enabled = False
.Visible = False
End If
End With
Next
Upvotes: 0
Reputation: 31
First, open the Excel sheet which you want hide the ribbon tab on, then press Alt+F11. Insert new code module and add following code:
Private Sub hide()
Application.ExecuteExcel4Macro "Show.ToolBar(""Ribbon"",False)
End sub
Upvotes: 3
Reputation: 459
To Activate a particular tab
In Microsoft Office 2010, you activate a custom tab by using the ActivateTab method of the IRibbonUI object
You use the ActivateTabMso method for built-in tabs and ActivateTabQ for tabs shared between multiple add-ins.
ActivateTabQ also requires an additional String-type parameter that specifies the namespace of the add-in
In XML specify
customUI onLoad="RibbonOnLoad" xmlns=etc
In VBA
Public gRibbonUI As IRibbonUI
Sub RibbonOnLoad(ribbon As IRibbonUI)
Set gRibbonUI = ribbon
End Sub
Then in code
gRibbonUI.ActivateTab "MyTabID"
gRibbonUI.ActivateTabMso "TabHome"
Upvotes: 4
Reputation: 6433
Try this XML for Excel I have tested:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab idMso="TabHome" visible="false" />
<tab idMso="TabInsert" visible="false" />
<tab idMso="TabFormulas" visible="false" />
<tab idMso="TabData" visible="false" />
<tab idMso="TabReview" visible="false" />
<tab idMso="TabView" visible="false" />
<tab idMso="TabDeveloper" visible="false" />
</tabs>
</ribbon>
</customUI>
Upvotes: 2
Reputation: 101
You can indeed hide/show ribbons using VBA. Here is an example:
<ribbon startFromScratch="false">
<tabs>
<!-- EXCEL BUILT-IN TABS -->
<tab idMso="TabDeveloper" getVisible="GetVisible">
<group idMso="GroupCode" visible="true"/>
<group idMso="GroupAddins" visible="true"/>
<group idMso="GroupControls" visible="true"/>
<group idMso="GroupXml" visible="true"/>
<group idMso="GroupModify" visible="true"/>
</tab>
</tabs>
</ribbon>
Setup your XML file.
Setup your VBA script.
Sub GetVisible(control As IRibbonControl, ByRef MakeVisible)
Select Case control.ID
Case "TabDeveloper": MakeVisible = True
Case "TabHome": MakeVisible = True
Case "TabInsert": MakeVisible = True
Case "TabPageLayoutExcel": MakeVisible = True
Case "TabFormulas": MakeVisible = True
Case "TabData": MakeVisible = True
Case "TabReview": MakeVisible = True
Case "TabView": MakeVisible = True
Case "TabAddIns": MakeVisible = True
Case "TabBackgroundRemoval": MakeVisible = True
End Sub
Tip: Be sure to close your Excel Workbook that includes the ribbon you are editing before editing the XML ribbon file. I have found that it sometimes erases my VBA code (I don't know why, it just does).
Upvotes: 10
Reputation: 11
You can use on the XML like these:
< ribbon startFromScratch="true" >
check this link:
http://www.rondebruin.nl/win/s2/win012.htm
Upvotes: 1
Reputation: 149295
How can I hide and show all the standard Excel ribbon tabs using VBA (not XML)
The answer is "YOU CAN'T".
AFAIK, you can't do that using VBA. Unfortunately VBA doesn't expose the tabs. The only options that you have are as shown in the image below
So you can work with the commandbar, commandbarButton, commandbarComboBox etc...
You can say that Set cbar = Application.CommandBars("Ribbon")
but after that, the problem that you will face is how to get a handle for the tabs.
What you can do with the Ribbon using VBA:
What you can't do with the Ribbon using VBA:
You can however use XML to achieve what you want. For example
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabReview" visible="false" />
</tabs>
</ribbon>
</customUI>
But I guess you do not want to go via the XML Route.
Upvotes: 11