Hello.
There is the registry keys for recent files:
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General\RecentFiles
How to get the value this key?
Thank you very much.
Hello.
There is the registry keys for recent files:
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General\RecentFiles
How to get the value this key?
Thank you very much.
Dear collegues!
I found my solution (below), maybe it will helpful for somebody:
Sub getSpecFolder_new()
Dim myPath As String
Dim objWSH
Dim bKey As String
Set objWSH = CreateObject("WScript.Shell")
bKey = objWSH.RegRead("HKCU\Software\Microsoft\Office\11.0\Common\General\RecentFi les")
myPath = Environ$("appdata") & "\" & "\Microsoft\Office\" & bKey 'Set the path.
With Dialogs(wdDialogFileOpen)
.Name = myPath
If .Display = -1 Then
MsgBox .Name
End If
End With
End Sub
If you want to do it without instantiating a Shell object ..
[VBA]bKey = System.PrivateProfileString("", _
"HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General", _
"RecentFiles")[/VBA]
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Tony, thank you very much. I will use this method (it is better).
Also, you can use the RecentFiles collection in Word itself.
[vba]
Dim j As Long
Dim MyList As String
For j = 1 To Application.RecentFiles.Count - 1
MyList = MyList & Application.RecentFiles(j) _
& vbCrLf
Next
MsgBox MyList
[/vba]
Hello. Thank you, but it inform me "run-time error 5152. Method 'Name' of object RecentFiles is failed"...
I just copied the code from my post above and ran it. It worked perfectly.
What version of Word are you using?
Sorry, you are using 2003, right? Office 11. Still, I thought 2003 still had RecentFiles as a legitimate collection.
I use WinXP and Word 2003. I use this macro simple:
[VBA]Sub rflist()
Dim j As Long
Dim MyList As String
For j = 1 To Application.RecentFiles.Count - 1
MyList = MyList & Application.RecentFiles(j) & vbCrLf
Next
MsgBox MyList
End Sub[/VBA]
It works prefectly in 2002. I guess the RecentFiles collection was removed from 2003.
here need use FileSystemObject
Gerry,
akokin is trying to read the registry to get the name of the folder where shortcuts to 'recent files' are kept, not trying to access Word's MRU list. Exactly what goes in this folder, I'm afraid, bemuses me.
For the record, the RecentFiles collection still exists in 2007.
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
I understand.
But why would there be a ""run-time error 5152. Method 'Name' of object RecentFiles is failed"..." on the code?
I don't see where it is being used - or trying to be used - but RecentFiles (the collection) does not have a Name property (RecentFile (the object) does).
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
"I don't see where it is being used - or trying to be used "
Hmmmm...
I use WinXP and Word 2003. I use this macro simple:
[vba]
Sub rflist()
Dim j As Long
Dim MyList As String
For j = 1 To Application.RecentFiles.Count - 1
MyList = MyList & Application.RecentFiles(j) & vbCrLf
Next
MsgBox MyList
End Sub [/vba]
Hello.
Very strangely! But on one computer (in my office) this code worked. But at home - not! I wonder...
Sorry, Gerry, I was being a bit slow. In my defence Anton does quote the message wrongly but I still should have seen it.
Anton -- This is really wierd. I suspect some corruption in your Word Data key Settings value, and especially so if it only happens on one computer. Alternatively, it could, I suppose, be a language issue - is there anything that the missing files have in common?
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Tony, I understood why I got error. Into list of recent files was one document which was deleted earlier. And I have one question: how to define existence of the files from the list of recent files?
Thank you.
Dir(FileName) is as easy as anything - but if RecentFile.Name gives an error you won't be able to do that - or anything except trap the error.
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Thank you. Yes, I used this function. And I will use the operator "On errorresume next". I think that it is right. Otherwise it not way.