How to add a custom Ribbon tab using VBA?

后端 未结 7 748
深忆病人
深忆病人 2020-11-22 14:47

I am looking for a way to add a custom tab in the Excel ribbon which would carry a few buttons. I chanced on some resources addressing it via Google but all look dodgy and o

7条回答
  •  礼貌的吻别
    2020-11-22 15:37

    I struggled like mad, but this is actually the right answer. For what it is worth, what I missed was is this:

    1. As others say, one can't create the CustomUI ribbon with VBA, however, you don't need to!
    2. The idea is you create your xml Ribbon code using Excel's File > Options > Customize Ribbon, and then export the Ribbon to a .customUI file (it's just a txt file, with xml in it)
    3. Now comes the trick: you can include the .customUI code in your .xlsm file using the MS tool they refer to here, by copying the code from the .customUI file
    4. Once it is included in the .xlsm file, every time you open it, the ribbon you defined is added to the user's ribbon - but do use < ribbon startFromScratch="false" > or you lose the rest of the ribbon. On exit-ing the workbook, the ribbon is removed.
    5. From here on it is simple, create your ribbon, copy the xml code that is specific to your ribbon from the .customUI file, and place it in a wrapper as shown above (...< tabs> your xml < /tabs...)

    By the way the page that explains it on Ron's site is now at http://www.rondebruin.nl/win/s2/win002.htm

    And here is his example on how you enable /disable buttons on the Ribbon http://www.rondebruin.nl/win/s2/win013.htm

    For other xml examples of ribbons please also see http://msdn.microsoft.com/en-us/library/office/aa338202%28v=office.12%29.aspx

提交回复
热议问题