AutoExec Not Loading Ribbon

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bullfrog83
    New Member
    • Apr 2010
    • 124

    AutoExec Not Loading Ribbon

    I have the following code in my AutoExec:

    Code:
        Dim strRibbonName As String, strXML As String
        
        strRibbonName = "customUI"
        strXML = "<customUI xmlns=""http://schemas.microsoft.com/office/2006/01/customui"">" _
            & "<ribbon startFromScratch=""true"" /></customUI>"
        
        Application.LoadCustomUI strRibbonName, strXML
    However, when I open my db the Ribbon still displays. I'm using an ADP which is why I'm not using a USysRibbons table.
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    I've never had any luck implementing a ribbon through code.. My db is always picky and wants it to be called from a table.

    But, everything looks in order except that the Ribbon tag may not be closed right.

    Try:

    Code:
        strXML = "<customUI xmlns=""http://schemas.microsoft.com/office/2006/01/customui"">" _ 
            & "<ribbon startFromScratch=""true""></ribbon></customUI>"

    Comment

    • bullfrog83
      New Member
      • Apr 2010
      • 124

      #3
      I found a way to load the ribbon from an xml file which I prefer. I call this function in my autoexec macro:

      Code:
      Public Function LoadRibbonsADP()
      On Error GoTo Error_Handler
          
          Dim strXMLPath As String
          Dim strXMLData As String
      
          'get the path to the ribbon and make sure it exists
          strXMLPath = CurrentProject.Path & "\customUI.xml"
          Debug.Assert (Len(Dir(strXMLPath)) > 0)
      
          'load the ribbon from disk
          Open strXMLPath For Input Access Read As #1
          strXMLData = Input(LOF(1), 1)
      
          'remove the byte order mark
          strXMLData = Mid(strXMLData, InStr(strXMLData, "<customUI"))
          Close #1
      
          ' Check the command line. If you pass "DEBUG" to the /cmd switch, load the ribbon with startFromScratch="false"
          If (Command$() = "DEBUG") Then
              strXMLData = Replace(strXMLData, _
                                  "startFromScratch=""true""", _
                                  "startFromScratch=""false""")
          End If
      
          LoadCustomUI "customUI", strXMLData
      
      Exit_Procedure:
          Exit Function
      Error_Handler:
          MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical
          Resume Exit_Procedure
      End Function

      Comment

      • Megalog
        Recognized Expert Contributor
        • Sep 2007
        • 378

        #4
        Excellent, thanks for posting a good working solution. Will be stealing this for my code archive right now =)

        Comment

        • bullfrog83
          New Member
          • Apr 2010
          • 124

          #5
          No problem! Keep in mind that this code works if your xml file is named customUI.xml. If it's named something else then you'll have to replace the "customUI" in the code with whatever you've named your file. I only have one ribbon in my db so customUI was good enough for me.

          Comment

          Working...