Pulling User Environment Settings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jtgarrison
    New Member
    • Jan 2010
    • 18

    Pulling User Environment Settings

    I'm trying to pull some user settings in VBA, but I'm not quite sure what the correct syntax is.

    I'd like to pull the logged on User Name's My Documents, no matter what version of Windows they are using...XP, 7, or 2003. I think the syntax is Environ("userna me"), but how do I get Username\My Documents regardless of what version?

    Thanks.
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Originally posted by jtgarrison
    I'm trying to pull some user settings in VBA, but I'm not quite sure what the correct syntax is.

    I'd like to pull the logged on User Name's My Documents, no matter what version of Windows they are using...XP, 7, or 2003. I think the syntax is Environ("userna me"), but how do I get Username\My Documents regardless of what version?

    Thanks.
    You can use Windows Script Host Object library to retrieve path to "MyDocument s" folder.

    Comment

    • jtgarrison
      New Member
      • Jan 2010
      • 18

      #3
      Actually, I figured it out....It's Environ("userpr ofile")&"\"&env iron("username" )&"\" &"My Documents".

      Thanks.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32636

        #4
        That's pretty close. I would use :
        Code:
        Replace("%P\My Documents", _
                "%P", _
                Environ("USERPROFILE")

        Comment

        Working...