Ribbon: add customUI14.xml and "turn on" ribbon in workbook

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
833
Office Version
  1. 365
Platform
  1. Windows
Ribbonmasters: Much feeling around in the dark got me to the point where I create a well-behaved customUI14.xml file and put it into the customUI folder in the workbook file manually. Of course nothing happens when I open the workbook. I'm missing something obvious that I overlooked or forgot during my extensive reading. I know that my xml is good because if I open the workbook containing my xml with RibbonX and then immediately save the workbook that the ribbon shows up when I re-open the workbook. So RibbonX is doing something other than adding/modifying the xml file to/in into the workbook?

In that regard, the best I saw re putting the xml into a workbook is VB, not VBA. I tried hacking it into VBA but I bet that I did a laughable job at best...I am mostly ignorant about Excel and most topics after all.

Here is the hack attempt.

VBA Code:
Public Sub XLAddCustomUI(ByVal fileName As String, _
                         ByVal customUIContent As String)
                        
    ' Add a custom UI part to the document.
    ' Use this sample XML to test:

    '<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
    '    <ribbon>
    '        <tabs>
    '            <tab idMso="TabAddIns">
    '                <group id="Group1" label="Group1">
    '                    <button id="Button1" label="Button1"
    '                     showImage="false" onAction="SampleMacro"/>
    '                </group>
    '            </tab>
    '        </tabs>
    '    </ribbon>
    '</customUI>

    ' In the sample XLSM file, create a module and create a procedure
    ' named SampleMacro, using this signature:
    ' Public Sub SampleMacro(control As IRibbonControl)
    ' Add some code, and then save and close the XLSM file. Run this
    ' example to add a button to the Add-Ins tab that calls the macro,
    ' given the XML content above in the AddCustomUI.xml file.

    'Using document As SpreadsheetDocument = _
        SpreadsheetDocument.Open(fileName, True)
        
        ' You can have only a single ribbon extensibility part.
        ' If the part doesn't exist, add it.
        'Dim part = document.RibbonExtensibilityPart
        
        'If part Is Nothing Then
        '    part = document.AddRibbonExtensibilityPart
        'End If
        
        'part.CustomUI = New CustomUI(customUIContent)
        'part.CustomUI.Save()
    
    'End Using
    
    Dim vDocument As SpreadsheetDocument
    
    Dim vPart As Variant
                        
    Set vDocument = SpreadsheetDocument.Open(fileName, True)

    With vDocument
    
        Set vPart = .RibbonExtensibilityPart
        
        If vPart Is Nothing Then
            vPart = document.AddRibbonExtensibilityPart
        End If
        
        With vPart
            .CustomUI = New CustomUI(customUIContent) '<= ERROR
            .CustomUI.Save()                          '<= ERROR
        End With

    End With
    
    With vDocument
        .Save
        .Close
    End With
    
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
What exactly are you needing help with ?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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