View Full Version : Save file to each users desktop?
option 08-06-2008, 06:55 AM Hey guys,
I'm trying to save a file to the desktop for all that use it. The problem is, since we're all on a network, and the path to each users desktop is going to be different (ex: C:\Documents and Settings\user\Desktop(where user is going to be different)). Is there a way to modify my code with a way to pick up the users path to their desktop? Or am I going to have to code it in?
Private Sub CommandButton2_Click()
Dim savename As String
savename = Range("e6").value 'This is the cell with the info I need in the file 'name
ActiveWorkbook.SaveAs "C:\workflow\" & Format(Date, "yyyymmdd") & "_" & savename & ".xls"
End SubThe "C:\workflow\" needs to change to the desktop. Thanks guys!!
namliam 08-06-2008, 07:18 AM Environ("Username") will give you their username which is your "missing link"
Happy hunting :)
chergh 08-06-2008, 07:21 AM Private Declare Function GetUserName _
Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer as String, nSize as Long) _
As Long
Public Function UserName() as String
Dim sName as String * 256
Dim cChars as Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left$(sName, cChars -1)
End If
End Function
Private Sub CommandButton2_Click()
Dim savename As String
savename = Range("e6").value 'This is the cell with the info I need in the file 'name
ActiveWorkbook.SaveAs "C:\Documents and Settings\" & username & "\Desktop\" & Format(Date, "yyyymmdd") & "_" & savename & ".xls"
End Sub
option 08-06-2008, 10:56 AM Environ worked! I've used that numerous times, why I didn't think of it...I'll never know!! haha, Thanks guys!
georgedwilkinson 08-06-2008, 12:06 PM Not related...you realize that storing files on a desktop actually degrades Windows overall performance, right? Better to save a shortcut on the Desktop and the file somewhere in "My Documents".
Additionally, the naming scheme has changed in Vista so your code is likely to break when one of your users moves to Vista.
rainman89 08-06-2008, 12:10 PM Not related...you realize that storing files on a desktop actually degrades Windows overall performance, right? Better to save a shortcut on the Desktop and the file somewhere in "My Documents".
Additionally, the naming scheme has changed in Vista so your code is likely to break when one of your users moves to Vista.
you dont say??? you mean having 500 documents on my desktop is slowing my computer down???:confused::confused::confused::eek::eek::ee k:
i always love seeing that
georgedwilkinson 08-06-2008, 12:16 PM Rotflol...
namliam 08-06-2008, 12:54 PM you dont say???
About a week ago...
My Customer:
I guess my 1.2 gig home grown amature over the top access database on my desktop is a problem???
Oh... yeah I do take 20 minutes to startup in the morning... what did you say? You can bring this down to 2 minutes? Great!!
Any my DB down to 20 meg?? Wow!!! You are a magician mr Mailman...
My toughts:
Yeah sure, just a matter of a compact ;)
10 minutes later:
Presto sir, your improved computer have fun.
Oh and by the way... it seems you have access to this and that database.
Customer:
Yeah I had a friend (who was fired months back) who granted me access.
My thoughts:
OK ? Guess I know why the guy got fired... This guy shouldnt have access to these databases... Could explain a data corruption or two we have been experiencing lately.
My Answer...
OK Cool... Have a nice day.
Back at the desk:
Kill user/pw
10 minutes later phone rings...
Customer: You fixed my computer, buy my DB dont work anymore :mad:
Me: Oh whats wrong??
Customer: It says unable to authenticate
Me: That means you dont have rights to the DB.
Let me check our systems.... What user did you have?
Customer: User? I dont know
Me: OK Let me check your credentials, No I cannot find your authorization to have access to this anywhere....
Do you have a copy??
Customer: Nevermind :(
option 08-07-2008, 11:28 AM Not related...you realize that storing files on a desktop actually degrades Windows overall performance, right? Better to save a shortcut on the Desktop and the file somewhere in "My Documents".
Additionally, the naming scheme has changed in Vista so your code is likely to break when one of your users moves to Vista.
A) The users desktops are locked down. They don't have access to ANY folders or shortcuts, hence saving on the desktop :)
B) Vista = for retards. We're not switch to Vista here aaaaaaaaaaaaaany time soon, but thanks!
georgedwilkinson 08-07-2008, 11:40 AM B) Vista = for retards. We're not switch to Vista here aaaaaaaaaaaaaany time soon, but thanks!
LOL, that makes me a retard! But I understand your statement and won't take it as an insult (I think).
Vista is the suckiest OS I believe I've ever had to use. I've had nothing but problems, except when playing video games.
But the point I was trying to make is that newer OSs are changing the "location" of users files. Since Vista has done it, you can be assured that the next OS that MS offers that doesn't suck (may it come sooner than later) will have it that way, too.
Unfortunately, you can no longer buy a new PC without Vista. An enterprise can just re-image new PCs...home business users cannot.
option 08-07-2008, 11:59 AM Oh I hear you there! And that was not intended to be an insult, sorry about that :). The way I see it: if you didn't say it, someone browsing this thread may not have known it and never would have, had you not said it!
|
|