setting current user logged in

G

George Quitugua

I'm trying to check to see if a file exists in Users
Profile folder in Windows 2000 (i.e. Docs &
Settin....\User\Folder - Users are using roaming profiles)
but am running into errors when trying to specify the
current user logged in. I'm trying to use %username% in
the following code:

If (Fsys.FolderExists("c:\winnt")) Then
TextFile = "c:\winnt\profiles\%UserName%\My
Documents\file.txt"
Else
TextFile = "C:\Documents and Settings\%UserName%\My
Documents\file.txt"

Also....should I be using %systemroot% instead of c:\winnt?

Any help is appreciated.

Thanks,

GQ
 
J

Jay Freedman

Hi, George,

VBA doesn't understand the environment string names like %username% the way
DOS batch files do. You have to use the Environ() function, like this:

TextFile = Environ("systemroot") & "\profiles\" & _
Environ("username") & "\My Documents\file.txt"
 
T

Thomas B. Johansen

do it like this

Sub show_my_document_path()

Set WshShell = CreateObject("WScript.Shell")
folder_name = WshShell.SpecialFolders("MyDocuments")

msgbox ("the path to your 'My document' is: " + folder_name)

End Sub


and you can change "MyDocuments" whit any of:

AllUsersDesktop
AllUsersStartMenu
AllUsersPrograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Programs
Recent
SendTo
StartMenu
Startup
Templates


Thomas Bøjstrup Johansen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top