PDA

View Full Version : Solved: How do you get the path of a currently open file?



SherryO
06-05-2007, 06:44 AM
I'm trying to modify a file that opens on startup. It's location would change from user to user. How do I get the path of the file that's already open? Thanks

Oorang
06-05-2007, 11:26 AM
Depends on the file type. But you can get the startup folder path like so:
Path = "C:\Documents and Settings\" & vba.Environ$("USERNAME") & "\Start Menu\Programs\Startup\"

SherryO
06-05-2007, 11:31 AM
Thanks, I'll give it a shot. You don't happen to know anything about MSProject and global.mpt, do you? I sure could use some help. Thanks again.

Oorang
06-05-2007, 11:36 AM
I know project. What are you trying to do?

mvidas
06-05-2007, 12:24 PM
Aaron,

FWIW, I'd go with something like msgbox environ("userprofile") & "\start menu\programs\startup\"As stupid as I think it is, some people (or businesses) change where their user files are located.
Also, checking the All Users directory (environ("allusersprofile")) for the startup file might not be a bad idea too, again depending on the setup.

Matt

SherryO
06-05-2007, 12:27 PM
I'm trying to add an open event to the global.mpt without overriding the existing file. I have a set of toolbars and menus that I want created / deleted when global.mpt is opened.

My company is one that moves the default startup directory. Thanks!

SherryO
06-05-2007, 01:25 PM
I used the Environ$(username) and it worked fine for my test machine, but it died on mine because my username has been changed since the originial install. How would I go about checking that, then giving a browse button / window for the user if it can't be found? Thank you!!

Oorang
06-05-2007, 05:16 PM
Did you try the user profile like Matt suggested? It's actually the better way to go.

SherryO
06-06-2007, 05:19 AM
I get runtime error 52, bad filename or number.
"C:\Documents and Settings\" & VBA.Environ("USERprofile") & "\Application Data\Microsoft\MS Project\11\1033\global.mpt" It's just a file copy statement. I can't post the whole thing because it has my company info in it... Thanks again.

Oorang
06-06-2007, 06:28 AM
Ahh well there is your problem then. USERPROFILE contains the path up to the username. To see what I am refering to do MsgBox VBA.Environ("USERprofile") All you really need to do is:VBA.Environ("USERprofile") & "\Application Data\Microsoft\MS Project\11\1033\global.mpt"You know there may be an easier way to go about this... What application are you hosting this code in?

SherryO
06-06-2007, 09:23 AM
Can you hear me dancing around like a fool??? It worked perfectly. Thank you so much. That would have taken forever to figure out!:>