Note that the "Users" directory is new as of Windows Vista. In Windows
XP and earlier, the folder name is "Documents And Settings". Vista
and Windows 7 provide backwards compatibility by aliasing "Documents
And Settings" to point to "Users", but the reverse is not true. You
would be best off using code like
Dim DesktopFolder As String
Dim N As Long
Dim UserName As String
UserName = Range("G5").Value
DesktopFolder = Environ("userprofile")
N = InStrRev(DesktopFolder, "\")
DesktopFolder = Left(DesktopFolder, N) & UserName & "\Desktop"
Debug.Print DesktopFolder
If you want to get the desktop folder for the current user, you can
simplify this to
Dim DesktopFolder As String
DesktopFolder = Environ("userprofile") & "\Desktop"
If you want a really ironclad way to do this, see the code and
download at
http://www.cpearson.com/Excel/SpecialFolders.aspx . It is
a lot of code, but allows you to get any of the special user folders
(Application Data, Program Files, Favorites, etc).
Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
On Sun, 16 May 2010 23:36:25 -0600, "Jim Berglund"
wrote:
I want to be able to open a file from any users desktop.
From my desktop, the command is
Workbooks.Open Filename:="C:\Users\Jim\Desktop\403.csv"
How do I automate this, using
UserName = Range("G5").Value
So that if the user enters 'Dave' into G5, the code line will change to
Workbooks.Open Filename:="C:\Users\Dave\Desktop\403.csv" ?
Thanks,
Jim Berglund