View Full Version : Make directory at Network Login name
VishalkumarT
07-09-2007, 04:02 AM
Dear Friends
I need your help regarding how to create a directory using Network Login Name.
I know we can make directory MyDirectory at C:\ using one-line code
MkDir "C:\MyDirectory\"
But suppose if I want to share my macro-code (in which I need to create directory while running it first time) amongst different users on a network, for example, users A,B and C log in into the network using their login names UsernameA, UsernameB and UsernameC respectively; and they have their network drive with their login name folder H:\Netowrk Username\ , then how can I make MyDirectory in this folder.
I mean on the network drive,
H:\Network Username\MyDirectory
where Network Username would be UsernameA for A, UsernameB for B and UsernameC for C.
I hope you would understand what I mean to write here.
Thank you once again.
Best Regards
Vishalkumar
Simon Lloyd
07-09-2007, 04:26 AM
Vishalkumar, i think its something like this:
MkDir "H:\"& Environ("UserName") & \MyDirectory"
Bob Phillips
07-09-2007, 04:30 AM
Simon,
You would need to do it in stages
MkDir "H:\" & Environ("UserName")
MkDir "H:\" & Environ("UserName") & "\MyDirectory"
Simon Lloyd
07-09-2007, 04:32 AM
Why the two stages Bob? (nice to hear from you!)
Bob Phillips
07-09-2007, 04:46 AM
Becuase it will fail if the parent directory does not already exist.
Done properly, it should have error handling in case either does/does not exist.
VishalkumarT
07-09-2007, 04:48 AM
Hi Simon
Hello xld
I tried to use both the alternatives shown here by you both.
But Compilation error was coming, so I changed it to
MkDir "H:\" & Environ("UserName") & "\MyDirectory"
by putting extra " after second & sign.
And then I tried to run it, but it shows error messages, path couldn't find.
I am wondering how does it recognise different UserNames with this code :bug:
Vishalkumar
Bob Phillips
07-09-2007, 04:50 AM
See my responses explaining this.
VishalkumarT
07-09-2007, 05:04 AM
But with this code
MkDir "H:\" & Environ("UserName")
MkDir "H:\" & Environ("UserName") & "\MyDirectory"
this error comes:
Run time error 75
Path/file access error
VishalkumarT
07-09-2007, 05:08 AM
Hello
By writing the code in this protection it works:
On Error Resume Next
MkDir "H:\" & Environ("UserName")
MkDir "H:\" & Environ("UserName") & "\MyDirectory"
On Error GoTo 0
Will it affect the other part of my code, I mean, wherever I will use MyDirectory to store some result or generated files in the code ?
Thank you so much...
:friends:
Bob Phillips
07-09-2007, 05:25 AM
Nope.
VishalkumarT
07-09-2007, 05:45 AM
Thank you once again to both of you :)
Hello
By writing the code in this protection it works:
On Error Resume Next
MkDir "H:\" & Environ("UserName")
MkDir "H:\" & Environ("UserName") & "\MyDirectory"
On Error GoTo 0
Will it affect the other part of my code, I mean, wherever I will use MyDirectory to store some result or generated files in the code ?
Thank you so much...
:friends:
I would probably do something along these lines:
If Dir("H:\" & Environ("UserName"), vbDirectory) = "" Then
MkDir "H:\" & Environ("UserName")
MkDir "H:\" & Environ("UserName") & "\MyDirectory"
ElseIf Dir("H:\" & Environ("UserName") & "\MyDirectory", vbDirectory) = "" Then
MkDir "H:\" & Environ("UserName") & "\MyDirectory"
Else
MsgBox "Directories Exist", vbOKOnly
End If
But that's just me. Depends on what you're trying to do.
VishalkumarT
07-10-2007, 02:54 AM
Nice things to learn.
Thanks everybody.
VishalkumarT
07-16-2007, 02:48 AM
Dear Friends
Now I am finding a strange problem (may be for me), I used the trick to find the destination folder on network, using the replies of this post, but i am finind an error, if I have windows/excel of different languages. Some of the network users have English version and some have German version of Excel or office.
I am using this code with a user defined button to activate it, this is "Custom Button" in English "Benutzerdefinierte Schaltfl?che" in German in the code.
I mean,
Set mycontrol = mybar.Controls.Item("Custom Button") ' for English version
or
Set mycontrol = mybar.Controls.Item("Benutzerdefinierte Schaltfl?che") ' for German version
May I know how I can educate the macro code, that if English version is there then do this and if German version is there then do that ? Though I want to use the same code for If and for Else If part, but just want to perform the action for both of these languages.
Many thanks for your precious time and help.
Vishalkumar
Bob Phillips
07-16-2007, 03:34 AM
Look at the value of
application.International(xlcountrysetting)
in the German version and test that. UK is 44, I guess US is 01, and Germany should be 49?
VishalkumarT
07-16-2007, 04:03 AM
Yes it is 49.
Thanks.
Let me check it.
VishalkumarT
07-16-2007, 04:24 AM
It is working :)
Thank you.
Best Regards
Vishalkumar
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.