Consulting

Results 1 to 11 of 11

Thread: Solved: How do you get the path of a currently open file?

  1. #1

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

    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

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    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\"

  3. #3
    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.

  4. #4
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    I know project. What are you trying to do?

  5. #5
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Aaron,

    FWIW, I'd go with something like [vba]msgbox environ("userprofile") & "\start menu\programs\startup\"[/vba]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

  6. #6
    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!

  7. #7
    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!!

  8. #8
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Did you try the user profile like Matt suggested? It's actually the better way to go.

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

  10. #10
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Ahh well there is your problem then. USERPROFILE contains the path up to the username. To see what I am refering to do [vba]MsgBox VBA.Environ("USERprofile")[/vba] All you really need to do is:[vba]VBA.Environ("USERprofile") & "\Application Data\Microsoft\MS Project\11\1033\global.mpt"[/vba]You know there may be an easier way to go about this... What application are you hosting this code in?

  11. #11
    Can you hear me dancing around like a fool??? It worked perfectly. Thank you so much. That would have taken forever to figure out!:>

Posting Permissions

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