Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ChangeFileOpenDirectory should point to a folder in the user profile

Status
Not open for further replies.

AlexFeddes

Programmer
Jan 17, 2009
22
NL
Instead of pointing to a fixed folder in for example Program Files (in Vista all folders in Program Files are read only), I want to open a file in the My Documents folder from the user that is logged in.

ChangeFileOpenDirectory "C:\Program Files\1-ACF Studytools\Handleiding\"
Documents.Open FileName:="ACF Studies introductie.doc"

I would like the first line ChangeFileOpenDirectory to point to My Documents\1-ACF Studytools\Handleiding\ in the user profile that is logged in. For example if I am logged in, it should point to C:\Users\Alex\Documents\1-ACF Studytools - but when my wife is logge din, it should point to C:\Users\My wife\Documents\1-ACF Studytools zijn.

It has to be a flexible reference to Documents within the documents of the user logged in {userdocs}.

Please advise,
Alex
 
As this is a code question, if the following does not help, please post to the VBA forum. Thanks.

I have to ask though, why are you using ChangeFileOpenDirectory?

Essentially the answer would be to get the username (as a string) and use it as part of your folder string.
Code:
Dim CurUser As String
CurUser = Environ("UserName")
Documents.Open FileName:="C:\Users\" & CurUser & _
   "\Documents\1-ACF Studytools\ACF Studies introductie.doc"

would open ACF Studies introductie.doc under the current logged-on user Documents folder - assuming of course the file DOES exist! And is in that folder!

Gerry
 
Dear all,
many thanks for your advice - I've found more than one satisfying answer.

This post can therefore be closed now.

Regards,
Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top