Consulting

Results 1 to 20 of 20

Thread: Solved: How to get value from registry?

  1. #1
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location

    Solved: How to get value from registry?

    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.

  2. #2
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    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

  3. #3
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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

  4. #4
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Tony, thank you very much. I will use this method (it is better).

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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]

  6. #6
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Hello. Thank you, but it inform me "run-time error 5152. Method 'Name' of object RecentFiles is failed"...

  7. #7
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I just copied the code from my post above and ran it. It worked perfectly.

    What version of Word are you using?

  8. #8
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Sorry, you are using 2003, right? Office 11. Still, I thought 2003 still had RecentFiles as a legitimate collection.

  9. #9
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    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]

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    It works prefectly in 2002. I guess the RecentFiles collection was removed from 2003.

  11. #11
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    here need use FileSystemObject

  12. #12
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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

  13. #13
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I understand.

    But why would there be a ""run-time error 5152. Method 'Name' of object RecentFiles is failed"..." on the code?

  14. #14
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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

  15. #15
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "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]

  16. #16
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Hello.
    Very strangely! But on one computer (in my office) this code worked. But at home - not! I wonder...

  17. #17
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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

  18. #18
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    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.

  19. #19
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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

  20. #20
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •