Access/VBA Library

ChangeRibbon

Changes the Ribbon XML to remove the standard Access ribbons and add a default backstage if no backstage has been defined.

Syntax

ChangeRibbon( XML )
Parameters
Name Type Description
XML String Required. The Ribbon XML to be changed.
Return value

String : The changed Ribbon XML.

Code
Private Function ChangeRibbon(XML As String) As String
    Dim pos As Long
    Dim bsXML As String
    ' Changing the value of the startFormScratch attribute from false to true
    ' makes sure the standard Access-ribbons will disappear
    XML = Replace(XML, _
                  "startFromScratch=" & Chr(34) & "false" & Chr(34), _
                  "startFromScratch=" & Chr(34) & "true" & Chr(34) & "")
    ' Check if some backstage logic is added to the Ribbon XML.
    ' If not then add an almost empty backstage to the XML.
    pos = InStr(XML, "<backstage")
    
    If pos = 0 Then
        ' Make sure only Print and Exit are available on the backstage
        bsXML = "<backstage>" & _
                ribbonBackstageTab("TabPrint", "true") & _
                ribbonBackstageButton("ApplicationOptionsDialog", "false") & _
                ribbonBackstageButton("FileExit", "true") & _
                "</backstage>"
        ' Add Backstage XML by replacing the closing tag of the Ribbon itself
        XML = Replace(XML, "</customUI>", bsXML & "</customUI>")
    End If
    
    ChangeRibbon = XML
End Function
XMLtag:XML