Solved Err (1 Viewer)

asadkhan

Registered User.
Local time
Today, 20:14
Joined
Oct 26, 2019
Messages
52
Hello everyone greetings

I have got the below code working for all users but one gets the error 5147 couldn’t find your file. Any help will be much appreciated. All three methods work for everyone else, I.e, Environ, CreateUser and API fosuser() function.

Code:
strUserName = environ("UserName")
    'strUserName = fosusername()
    strUserName = CreateObject("wscript.network").UserName
 
    strPath = Me.txtFolder
 
    Set wApp = New Word.Application
     
    Set wDoc = wApp.Documents.Open("C:\Users\" & strUserName & "\Desktop" & "\" & "NoteTemplate.docx")
 
Last edited:

Isaac

Lifelong Learner
Local time
Today, 12:14
Joined
Mar 14, 2017
Messages
8,778
You would be surprised how often I've worked at companies where MOST people's path to the desktop is the same, but SOME people's is not.
A prime example is when the I.T. department comes in an deletes their windows profile and re-creates it, but leaves the Desktop the same as it was.
Another example is when only some but not all people are using OneDrive, which fu***s up peoples environment variable paths pretty royally.
Another example is when someone is hired as a contractor and their username is c_billjohnson, but later gets hired full time permanent and I.T. changes their log in username to perm_billjohnson.......but their desktop path remains the same as it used to be.

The root cause is , the path to that one person's desktop is NOT c:\users\username\desktop

You should use this instead:

Createobject("WScript.Shell").SpecialFolders("Desktop")
...."aircode" that is above, hope I got the syntax perfect, if not someone with a better memory correct me
 

asadkhan

Registered User.
Local time
Today, 20:14
Joined
Oct 26, 2019
Messages
52
You would be surprised how often I've worked at companies where MOST people's path to the desktop is the same, but SOME people's is not.
A prime example is when the I.T. department comes in an deletes their windows profile and re-creates it, but leaves the Desktop the same as it was.
Another example is when only some but not all people are using OneDrive, which fu***s up peoples environment variable paths pretty royally.
Another example is when someone is hired as a contractor and their username is c_billjohnson, but later gets hired full time permanent and I.T. changes their log in username to perm_billjohnson.......but their desktop path remains the same as it used to be.

The root cause is , the path to that one person's desktop is NOT c:\users\username\desktop

You should use this instead:

Createobject("WScript.Shell").SpecialFolders("Desktop")
...."aircode" that is above, hope I got the syntax perfect, if not someone with a better memory correct me
Thanks mate this really quick, I am going to put this in and check with the user tomorrow and will report back.
much appreciated.
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:14
Joined
Sep 21, 2011
Messages
14,340
Why not just check their path first?
 

asadkhan

Registered User.
Local time
Today, 20:14
Joined
Oct 26, 2019
Messages
52
I have it was same like it was for everyone else except of course they have their own user abc.def
I have tested mr. Isaac’s suggestion it is working fine for me. See what comes tomorrow for them. Hopefully it I will work for them. I have 67 people who had no problem but this is the only person who had it.
Thank you Mr Gasman, on number of occasions you codes had helped me thanks for that
 

asadkhan

Registered User.
Local time
Today, 20:14
Joined
Oct 26, 2019
Messages
52
I have tested mr. Isaac’s suggestion it is working fine for me. See what comes tomorrow for them. Hopefully it I will work for them. I have 67 people who had no problem but this is the only person who had it.
Thank you Mr Gasman, on number of occasions you codes had helped me thanks for that
Morning Mr Isaac
That did the trick, all good. Thank you for your help.
As ever thank forum
Have a good day.
 

Isaac

Lifelong Learner
Local time
Today, 12:14
Joined
Mar 14, 2017
Messages
8,778
glad to help have a nice day and Merry Christmas
 

Users who are viewing this thread

Top Bottom