Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jun 2001
    Location
    New York, New York, Lebanon
    Posts
    1,449
    Thanks
    1
    Thanked 1 Time in 1 Post

    Finding 'My Documents' (VBA 6.x)

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Loungers

    I know there are APIs to find system folders, like the folder that contains the installation of Windows, or the temp folder and what have you.

    But I need to look for the "My Documents" folder via code.

    I am mostly using Windows 2000 pro, but if the API or the code is different for different windows, then I would like to know that.

    Any ideas?

    TIA

    Wassim
    <img src=/S/compute.gif border=0 alt=compute width=40 height=20> in the <img src=/S/bagged.gif border=0 alt=bagged width=22 height=22>

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Finding 'My Documents' (VBA 6.x)

    If you can use scripting, try the following function :

    Function GetSpecialFolderPath(strFolder) As String
    Dim wshShell
    Set wshShell = CreateObject("Wscript.Shell")
    GetSpecialFolderPath = wshShell.specialfolders(strFolder)
    Set wshShell = Nothing
    End Function

    For My Documents you can use :

    GetSpecialFolderPath("MyDocuments") - note no space in My Documents.

    Andrew C

  3. #3
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Finding 'My Documents' (VBA 6.x)

    Hans,

    Using the following call to your API code

    GetSpecialFolder(CSIDL_PERSONAL)

    will return the path to the current users My Documents path.

    Andrew

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Finding 'My Documents' (VBA 6.x)

    Error corrected by HansV - thanks, Andrew!

    Copy the code from the attached text file into a standard module. Use GetSpecialFolder(CSIDL_PERSONAL) to retrieve the default document path of the current user.

    Code from ALLAPI

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Finding 'My Documents' (VBA 6.x)

    Andrew,

    Yes, of course. I had been playing around with the other constants and copied the wrong one into my reply. I have now corrected it. Thanks for the heads up! <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

Posting Permissions

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