Avoid adding a refence to the MRU list

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15810
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Avoid adding a refence to the MRU list

Post by ChrisGreaves »

Following on from the thread remove a non-existent template from the MRU list, of greater interest (to me) is how to inhibit MSWord (2003 or, at a pinch, 2016) from augmenting its Most Recently Used File List (File1-File9/50).
I have my own application that has its own Most Recently Used File List; I harvest data from RecentFiles folders and Registry settings. I trap File Save/Close/Open and have an option to Disable this utility when I am processing a batch of files that need not appear in my Most Recently Used Files list.
I have another bit of code that periodically saves an Audit Trail of every document being edited. This code is smart enough to Disable my Most Recently Used Files data, but sadly, these audit trail versions (“Planning.doc_20170716_1419_05.doc”, “Planning.doc_20170716_1420_06.doc”, “Planning.doc_20170716_1421_07.doc” and so on) populate my MSWord(2003) File list of Most Recently Used files.
Essentially, immediately before issuing a “doc.SaveAs” I’d like to tell MSWord to stop listening for a second or two.

Cheers
Chris
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed

User avatar
HansV
Administrator
Posts: 78917
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Avoid adding a refence to the MRU list

Post by HansV »

You can disable the built-in MRU feature by setting "Show this number of recent documents" to 0. In Word 2010 and later, this setting is in File > Options > Advanced, in the Display section. But this clears the list entirely.

In VBA:

RecentFiles.Maximum = 0
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15810
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Avoid adding a refence to the MRU list

Post by ChrisGreaves »

HansV wrote:You can disable the built-in MRU feature by setting "Show this number of recent documents" to 0. In Word 2010 and later, this setting is in File > Options > Advanced, in the Display section. But this clears the list entirely.
Thanks Hans. I'll give this a try, but as you suggest it is too broad a brush for my house-cleaning. I really want to inhibit individual files from appearing in the list.
I still find MSWord's MRUse list useful, especially while I am in a single MSWord session.
Its usefulness is reduced when I start a new session.
Thanks again.
Chris
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed

User avatar
HansV
Administrator
Posts: 78917
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Avoid adding a refence to the MRU list

Post by HansV »

The SaveAs method has a Boolean argument AddToRecentFiles. If you specify False, the document won't be added to the MRU list:

ActiveDocument.SaveAs FileName:="...", AddToRecentFiles:=False
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15810
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Avoid adding a refence to the MRU list

Post by ChrisGreaves »

HansV wrote:The SaveAs method has a Boolean argument AddToRecentFiles. ...
(For the 345th time) "How come I didn't spot this?"

:guilt: :grovel: ;ashamed:
Thanks :thankyou: :thankyou:
Chris
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Avoid adding a refence to the MRU list

Post by macropod »

The Documents.Open method also supports AddToRecentFiles:=False - but I'm sure you already knew that, too....
Paul Edstein
[Fmr MS MVP - Word]

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15810
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Avoid adding a refence to the MRU list

Post by ChrisGreaves »

HansV wrote:The SaveAs method has a Boolean argument AddToRecentFiles.
You know, sometimes I really hate you guys ...
MR4U.png
:grin: :thankyou:

Code: Select all

doc.SaveAs strAuditTrail, , , , blncAddToRecentFiles, , blncReadOnlyRecommended
doc.SaveAs strResult, , , , blncAddToRecentFiles
You do not have the required permissions to view the files attached to this post.
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15810
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Avoid adding a refence to the MRU list

Post by ChrisGreaves »

macropod wrote:The Documents.Open method also supports AddToRecentFiles:=False - but I'm sure you already knew that, too....
The astute programmer will check the Read-Only properties of the file by right-clicking on the file name in Windows Explorer, and discover that the read-only bit is NOT set. This read-only property therefore does not belong to the file container, but to the file contents.
MRU005.png
Tools, Options, Security is the answer.
A quick tweak to the Visual Basic for Applications code and we are back in business.

Code: Select all

doc.SaveAs strAuditTrail, , , , blncAddToRecentFiles, , blncReadOnlyRecommended
doc.ReadOnlyRecommended = False ' 20170719 Am I leaving this switch turned on?
doc.SaveAs strResult, , , , blncAddToRecentFiles
MsgBox doc.FullName & doc.ReadOnlyRecommended
Thanks, Paul.
You do not have the required permissions to view the files attached to this post.
I’ve been tidying the junk out of my shed for five years, and now can hardly get into the shed