Can I dynamically update the officeMenu on the Office Ribbon (like I do in the ribbon tabs)?

mhnatt
mhnatt used Ask the Experts™
on
I'm trying to make my own "recent files" list in my custom Office Ribbon, specifically in the <officeMenu> or "Big round Office Button" section.

I ALREADY HAVE A FUNCTION TO GENERATE THE DATA (list of files) BUT MY PROBLEM IS that I need a way to dynamically update the ribbon "specifically" the OfficeMenu (button) section dynamically.

For those who will say that this by default already shows a recent files list, I am doing this on a custom front-end Access application in runtime, to show the most recent backends that have been opened.

While I can easily make dynamic menus in the ribbon using the <dynamicMenu> tag, it appears that the officeMenu section is very restrictive.  I was hoping to do something like (see the last line):

<ribbon startFromScratch="true">
  <officeMenu>
      <button id="ofm_NewBackEnd" imageMso="FileNew" label="New Back End" onAction ="rbnfn_NewBackEnd"/>
      <dynamicMenu id="rbndynRecent" size="large" label="Recent Files" imageMso="ImportTextFile" getContent="rbnfn_GetRecentFiles" />

But as I expected, the officeMenu does NOT like a dynamicMenu.  Any ideas?

Thanks!

<ribbon startFromScratch="true">
  <officeMenu>
      <button id="ofm_NewBackEnd" imageMso="FileNew" label="New Back End" onAction ="rbnfn_NewBackEnd"/>
      <dynamicMenu id="rbndynRecent" size="large" label="Recent Files" imageMso="ImportTextFile" getContent="rbnfn_GetRecentFiles" />

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2008

Commented:
mhnatt,

In the many years I have been posting on Experts Exchange I have never referred someone elsewhere...I suppose there is always a first time. The best person I know to answer your question is the Microsoft Excel MVP Ken Puls who authored the book "RibbonX - Customizing the Office 2007 Ribbon". I can't post his email address here but I can give you a few links. This one is his blog:

http://www.excelguru.ca/blog/

And this is a profile on another Q&A site:

http://www.vbaexpress.com/forum/member.php?u=573

I'll leave it to you to figure out how to contact him.

Kevin
Commented:
Hi there,

I used a slightly different syntax for things, but hopefully this still makes sense.

I took your XML and copied it into the CustomUI Editor, then tried to validate it.  It failed immediately, telling me that the size attribute was not declared.  Sure enough, I removed it from the code, and mocked up a (simple) sample, as shown in the code snippets below.

It's actually interesting this... We covered the dynamicMenu in detail starting on page 310 of our book, and the size attribute IS an allowable element in most cases.  I was not aware until now, however, that it is NOT allowable in the officeMenu element.

At any rate, get rid of that attribute, and you should be fine.  I'd definitely recommend validating your code in the CustomUI editor before you implement it in Access.  You'll find that it saves you a world of hurt.  :)

XML:
 
<officeMenu>
      	<dynamicMenu id="rxdmnuRecentFiles" 
			label="Recent Files" 
			imageMso="ImportTextFile"
	 		getContent="rxdmnu_GetRecentFiles" />
	</officeMenu>
 
VBA:
'Callback for rxdmnuRecentFiles getContent
Sub rxdmnu_GetRecentFiles(control As IRibbonControl, ByRef returnedVal)
returnedVal = "<menu xmlns=""http://schemas.microsoft.com/office/2006/01/customui"">" & _
    "<button idMso=""FileOpenDatabase""/></menu>"
End Sub

Open in new window

Author

Commented:
Whoa, thanks a lot Ken.  If you can imagine, I was quite thrilled to see that it can be done.  I had already begun to plan out how to do a Recent List via some other method (which, would have been unorthodox).  Now if Microsoft would just allow us to change the button icon we'd be in great shape!  Thanks so much again Ken!  Your solution alone has made my membership in EE worth it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial