Adding commandbar controls to the Ribbon QAT via VBA ?

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
9,621
Office Version
  1. 2016
Platform
  1. Windows
I am experimenting with programming the ribbon and I want to add at runtime two new commandbar controls to the QAT namely the FileNewDefault and the Spelling controls.

The code below generates the xml string and writes the xml string to the Excel.OfficeUI file.

However the controls do not load and the QAT remains unaffected even after closing and reopening excel.

When I open the OfficeUI file, it contains the new xml but has no effect.

I am sure I am missing something here as this is new territory to me .. Does anyone knows what is going on ?

Regards.

HTML:
Sub AddControlToQAT()

    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=" & Chr(34) & "http://schemas.microsoft.com/office/2009/07/customui" & Chr(34) & ">" & vbNewLine
    ribbonXML = ribbonXML + "  <mso:ribbon>" & vbNewLine ''
    ribbonXML = ribbonXML + "    <mso:qat>" & vbNewLine ''
    ribbonXML = ribbonXML + "      <mso:sharedControls>" & vbNewLine ''
    ribbonXML = ribbonXML + "           <mso:control idQ=" & Chr(34) & "mso:FileNewDefault" & Chr(34) & " Visible=" & Chr(34) & "true" & Chr(34) & "/>" & vbNewLine
    ribbonXML = ribbonXML + "           <mso:control idQ=" & Chr(34) & "mso:Spelling" & Chr(34) & " Visible=" & Chr(34) & "true" & Chr(34) & "/>" & vbNewLine
    ribbonXML = ribbonXML + "      </mso:sharedControls>" & vbNewLine ''
    ribbonXML = ribbonXML + "    </mso:qat>" & vbNewLine ''
    ribbonXML = ribbonXML + "   /mso:ribbon>" & vbNewLine ''
    ribbonXML = ribbonXML + "</mso:customUI>" & vbNewLine ''
    
    Debug.Print ribbonXML
    
    Open path & fileName For Output Access Write As hFile
        Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hFile]#hFile[/URL] , ribbonXML
    Close hFile


End Sub
 
Last edited by a moderator:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
The forum doesnt show the xml code .. here is a snapshot of the code :


 
Last edited:
Upvote 0
HTML:
Sub LoadCustRibbon1()
Dim hFile As LongDim path As String, fileName As String, ribbonXML As String, user As String
hFile = FreeFileuser = Environ("Username")path = "C:\Users\" & user & "\AppData\Local\Microsoft\Office\"fileName = "Excel.officeUI"
ribbonXML = "" & vbNewLine
ribbonXML = ribbonXML + "  " & vbNewLineribbonXML = ribbonXML + "    " & vbNewLineribbonXML = ribbonXML + "    " & vbNewLineribbonXML = ribbonXML + "      " & vbNewLineribbonXML = ribbonXML + "        " & vbNewLineribbonXML = ribbonXML + "          " & vbNewLineribbonXML = ribbonXML + "        " & vbNewLineribbonXML = ribbonXML + "      " & vbNewLineribbonXML = ribbonXML + "    " & vbNewLineribbonXML = ribbonXML + "  " & vbNewLineribbonXML = ribbonXML + ""
ribbonXML = Replace(ribbonXML, "'", Chr(34))
Debug.Print ribbonXMLOpen path & fileName For Output Access Write As hFilePrint [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=hFile]#hFile[/URL] , ribbonXMLClose hFile
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,897
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top