I have the following VBA script to add a custom ribbon, I am aware that there is s custom UI app available, but I like VBA.
I want to add a second group to the tab, however I am not sure how to achieve it.
I want to add a second group to the tab, however I am not sure how to achieve it.
VBA 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='JayeTab' label='Jaye' insertBeforeQ='mso:TabInsert'>" & vbNewLine 'Change - label='Jaye' - To Your Tab Name ie. Jaye
ribbonXML = ribbonXML + " <mso:group id='reportGroup' label='Jaye' autoScale='true'>" & vbNewLine
ribbonXML = ribbonXML + " <mso:button id='runReport' label='Testing' " & vbNewLine
ribbonXML = ribbonXML + "imageMso='AppointmentColor3' onAction='TestingButton'/>" & 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
Sub ClearCustRibbon()
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"">" & _
"<mso:ribbon></mso:ribbon></mso:customUI>"
Open path & fileName For Output Access Write As hFile
Print #hFile, ribbonXML
Close hFile
End Sub
Sub TestingButton()
MsgBox "Test 1 Works"
End Sub
Sub TestingButton2()
MsgBox "Test 2 Works"
End Sub