Roca
Roca

Reputation: 69

Hide specific Ribbon Excel VBA

I created a new Ribbbon via macro (NOT via Custom UI Editor), all works fine, however, I need to hide the usual excel standard ribbon (file,Review,Developer and etc...).

This is my code:

Sub LoadCustRibbon()

Dim hFile As Long
Dim path As String, fileName As String, ribbonXML As String, user As String

hFile = FreeFile
user = Environ("Username")
path = "C:\Users\" & user & "\AppData\Local\Microsoft\Office\"
fileName = "Excel.officeUI"

ribbonXML = "<mso:customUI      xmlns:mso='http://schemas.microsoft.com/office/2009/07/customui'>" & vbNewLine
ribbonXML = ribbonXML + "  <mso:ribbon>" & vbNewLine
ribbonXML = ribbonXML + "    <mso:qat/>" & vbNewLine
ribbonXML = ribbonXML + "    <mso:tabs>" & vbNewLine
ribbonXML = ribbonXML + "      <mso:tab id='reportTab' label='Menu' insertBeforeQ='mso:TabFormat'>" & vbNewLine
ribbonXML = ribbonXML + "        <mso:group id='reportGroup' label='Options' autoScale='true'>" & vbNewLine

ribbonXML = ribbonXML + "          <mso:button id='runReport' label='Frontpage' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='AppointmentColor3'      onAction='Callback1'/>" & vbNewLine


ribbonXML = ribbonXML + "        </mso:group>" & vbNewLine


ribbonXML = ribbonXML + "      </mso:tab>" & vbNewLine

ribbonXML = ribbonXML + "    </mso:tabs>" & vbNewLine

ribbonXML = ribbonXML + "  </mso:ribbon>" & vbNewLine
ribbonXML = ribbonXML + "</mso:customUI>"

ribbonXML = Replace(ribbonXML, """", "")

Open path & fileName For Output Access Write As hFile
Print #hFile, ribbonXML
Close hFile

End Sub

I tried adding this line , but it did not work, no error message, just nothing happens:

ribbonXML = ribbonXML + "    <tab mso:tab label ='file' visible='false'>"

Upvotes: 1

Views: 1202

Answers (1)

aduguid
aduguid

Reputation: 3195

You can hide specific tabs with this line. Add it before your custom tab in XML.

<tab idMso="TabDeveloper" getVisible="GetVisible"/> 

Upvotes: 1

Related Questions