none
VBA code which creates a Word ribbon tab listing recent documents RRS feed

  • Question

  • Has anyone seen any VBA code which creates a Word ribbon tab listing recent documents? I find the recent document list at the bottom of Backstage under the File tab is too far away and the one in the jump list is too much of a moving target. I can't find a command in the ribbon customization which does it.

    I asked this question on Google Groups and a Microsoft MVP suggested I come here and ask it. If there is a better place to ask this tell me, I really don't know how to code but I sometimes have been able to modify other people's code to get it to do what I want.

    I recently upgraded from Word 2002 where I had a menu which was nothing but the recent documents list. In fact, I have spent the past month making Word 2013 look and act as much as the Word I had been using for ten years, auto-hiding the ribbon to make it act more like menus and loading up my Quick Access toolbar with commands. I even recently figured out how to edit the right-click menu which seems to go against Microsoft’s wishes.

    Saturday, July 20, 2013 4:28 AM

All replies

  • Well, there's a command you can add to your QAT (or to a Ribbon tab) in the "File" category of Options/Customize Ribbon that will take you directly to the list of Recent files (the "Open" tab in the Backstage), where recent files are listed by default: "Open". That's what I use. It seems to me that's just as "close" as putting button in the Ribbon if you're auto-hiding the Ribbon...

    It is possible to make a list of recent files using VBA, but you need to understand how to work with Ribbon XML in order to add a menu to your Ribbon that will display such a list as a menu. It doesn't sound like you've worked with that, yet, so you may want to first review the information in the 3-part documentation Customizing the 2007 Office Fluent Ribbon for Developers .

    The basic code for looping the list of recent files that can be modified to generate a menu together with Ribbon XML:

    Sub RecentFileList()
        Dim rf As RecentFile
        For Each rf In RecentFiles
            Debug.Print rf.path & "\" & rf.Name
        Next
    End Sub

    Right-click menus: It's not that Microsoft doesn't want you changing them, per se. It's more that they feel "the casual user" ends up "making a mess" that support has to help clean up if it's too simple. Since Office 2010, the "correct" way is to define Ribbon XML for the context menues. Basically, the same way one defines a Ribbon that is part of an add-in or travels with a document. (As opposed to the tools Office 2013 provides for making local, user adjustments, which is probably what you're using?)


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, July 20, 2013 10:21 AM
    Moderator
  • Thank you very kindly for all help, but there are a couple of problems. The Open command doesn’t take you to Recent Documents if you have the word options set to “Don’t show Backstage when opening or saving files.” I did this because the basic task of getting to the files I want to open went from being one click to four clicks away. (File/Open/Computer/Folder)

    I also notice that clicking on File ribbon tab defaults to Info so the Backstage Recent Documents list is two clicks away. I thought I would try recording a macro to open the Backstage Recent Documents list but the recorder can’t see Backstage, it only sees the document I have to open to get back to where I can stop the recorder. I get something like “RecentFiles(7).Open.”

    “in order to add a menu to your Ribbon that will display such a list as a menu.”

    I actually don’t want to create traditional vertical menu in a ribbon tab. I want to create an entire ribbon tab that gets populated with recent documents horizontally.

    For example, I have recreated my trusty old Work menu which I have had since Word 5.1 for Macintosh by creating a custom ribbon tab named Work in which I put commands to open my favorite documents. I like to think of my Work tab as a menu that opens sideways rather than vertically. This is how I view all the ribbon tabs and I rely mostly on keyboard shortcuts and the Quick Access Toolbar to reach commands.

    When I start feeling like a pest on Microsoft bulletin boards, I remind myself I would have gotten this done in five minutes in Word 2002. So far my upgrade to Word 2013 has removed many features I used every day and it feels more like a downgrade and a big step backwards.

    Saturday, July 20, 2013 8:06 PM
  • Note that I'm not trying (very hard) to talk you out of something. Just searching for the least troublesome way for you to get where you need to be...

    Open/Save commands: an alternative to the option you've set that makes my first suggestion inviable would be to use macros attached to buttons that display the Open and Save As dialog boxes directly, instead of the Backstage. The following line of code will display the File/Open dialog box directly, just put it in a macro and assign it to a button in the QAT and/or Ribbon:

    Dialogs(wdDialogFileOpen).Show

    For Save As:

    Dialogs(wdDialogFileSaveAs).Show

    << I want to create an entire ribbon tab that gets populated with recent documents horizontally. >>

    Mmmm. I assume you'd want to see the names of the documents? In that case you certainly do require Ribbon XML since I assume that the names of the documents could change. So I still stand by my recommendation that you first familiarize yourself with that three-part documentation. You'll want to pay special attention to onAction and getLabel callbacks. Also, you'll want to download the free Custom UI Editor, which will make constructing and integrating the Ribbon XML into a template easiser (to be loaded as an add-in).

    The code I provided above that loops through the RecentDocuments collection is still the basis.

    Note that you do need to place all the buttons you require into the Ribbon XML at Design time. It's not possible to create buttons on the fly, you can only make existing ones invisible/visible if you don't always want to see n buttons.


    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, July 21, 2013 1:21 PM
    Moderator
  • For anyone who's interested, I was about to give up on the whole idea until I realized the Word 2013 Backstage recent files list was okay and I remembered the Sendkeys method.

    I thought there must be a simple VBA command similar to how you can show Word dialog boxes for the ribbon like Ribbon(wdRibbonFileRecent).Show, but alas I couldn’t find one. I had to use Sendkeys because if you turn off the Backstage view even the keyboard command  FileOpenUsingBackstage command I found in customize keyboard won’t work. Using “ SendKeys "%fo%" " to do what I wanted is about as graceful as using duct tape to fix a car bumper, there has got to be a better way.

    Thursday, July 25, 2013 6:24 AM
  • About as close as you can get is to use this line of code in your macro

    CommandBars.ExecuteMso("FileOpenUsingBackstage")


    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, August 1, 2013 4:42 PM
    Moderator
  • I posted a solution to this here:

    http://answers.microsoft.com/en-us/office/forum/office_2013_release-word/open-recent-files-command-on-quick-access-toolbar/c60fc37f-6e2c-442d-845d-321324beceae

    This allows you to directly modify the QAT to have the Open Recent Files icon available like it was in previous versions.  Sorry for the lack of a hyperlink, the site won't allow me to post one until I've been verified.

    Friday, December 26, 2014 4:13 PM
  • I'm trying to do the same thing in Word 2016 (i.e. create my own button to show the Recent Files in the Backstage) and found that:

    CommandBars.ExecuteMso ("FileOpenUsingBackstage")

    throws the error message:

    Run-time error "'5':  Invalid procedure call or argument.

    Can you tell me what would work in Word 2016?

    The reason I'm trying to do this is that I don't like the icon for recent files in Word 2016; it looks like a squished bug. My other idea was to try and change the icon for the recent files, but I found that using the idMSO means I cannot change the icon in the ribbon XML.

    BTW, I know I can create a user form as suggested here, but I really just want to get to the recent files backstage.

    Thanks, 

    Stuart

    Friday, May 5, 2017 12:35 AM