Home > Articles > Home & Office Computing > Microsoft Applications

This chapter is from the book

Opening the Most Recently Used Document at Startup

Word's RecentFiles object represents the collection of most recently used files displayed in the Recent Documents list. Each item on this list is a RecentFile object. You specify a RecentFile object by using RecentFiles(Index), where Index is an integer that specifies the file you want to work with. The most recently used file is 1, the second most recently used file is 2, and so on.

When you close a Word session, the document you last made changes to becomes the most recently used document. There's a good chance that you'll want to continue working on that document the next time you start Word. Therefore, it would be handy to have Word open the most recently used file each time you start the program.

If you want Word to run some code each time it's started, open the Visual Basic Editor (either by choosing Developer, Visual Basic or by pressing Alt+F11), click the Normal project in the Visual Basic Editor's Project Explorer, and then create a new module (by choosing Insert, Module) named AutoExec. In this module, create a Sub procedure named Main and enter your code in that procedure. Listing 3.6 shows such a procedure:

Listing 3.6. A Procedure That Opens the Most Recently Used Document

Sub Main()
End Sub
  • + Share This
  • 🔖 Save To Your Account