+ Reply to Thread
Results 1 to 5 of 5

Can I Get C:\Users\ Folder Name Using VBA??

  1. #1
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Can I Get C:\Users\ Folder Name Using VBA??

    Is there any way to get a user's "folder name" using VBA in Excel?
    For example, suppose a user (Joe Smith) has a personal folder (underneath the C:\Users directory) that is C:\Users\JSmith.
    I tried using Application.Username but that gives me (for example) "Joseph R. Smith", which I'm guessing is the name specified when setting up Excel.
    How do I get the actual "user folder" name for the current user?

    Reason: I need to create a filepath for saving a file, but the Excel file that's running is on a Sharepoint site, so ThisWorkbook.Path returns a URL (which Excel rejects as a bad file name if I try to use it to save a file). I've tried to convert it to a UNC, but that's not working either. Apparently, there is a folder on the C: drive which is a copy of (or some kind of link to) the Sharepoint site, so I want to use THAT filepath to save the file. I know exactly how to construct that filepath, EXCEPT for the "user folder" name, which is different for each user (so it's not something I can hardcode into the file).

    Any help / suggestions would be GREATLY appreciated!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Can I Get C:\Users\ Folder Name Using VBA??

    Please Login or Register  to view this content.
    will return the path to user's default folder. Ex:

    Please Login or Register  to view this content.
    gives

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Can I Get C:\Users\ Folder Name Using VBA??

    Try, Environ("Userprofile")

  4. #4
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Re: Can I Get C:\Users\ Folder Name Using VBA??

    Thanks to both of you for the solution!

  5. #5
    Spammer
    Join Date
    10-23-2012
    Location
    Adelaide, Australia
    MS-Off Ver
    Excel 2003, Office 365
    Posts
    1,237

    Re: Can I Get C:\Users\ Folder Name Using VBA??

    No problems. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. List of users access right to a folder
    By P3tlock in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-29-2022, 06:21 AM
  2. [SOLVED] Save file to users Temp folder, attach it to email then Kill file from temp folder
    By MagicMan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-18-2022, 09:13 AM
  3. Create folder on Desktop - work on all users computer
    By GeekBlueNose in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-13-2022, 01:06 AM
  4. How to prevent other users deleting the files or folder
    By ha suong in forum Excel General
    Replies: 1
    Last Post: 08-14-2013, 12:28 AM
  5. Multiple users accessing Excel file on shared folder.
    By daverskully in forum Excel General
    Replies: 1
    Last Post: 04-04-2008, 05:11 PM
  6. users with access to folder
    By wally6020 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2008, 06:49 PM
  7. linking data from network users folder
    By jermsalerms in forum Excel General
    Replies: 2
    Last Post: 11-04-2006, 03:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1