Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Username in path
I want to create a button to save the file to the user desktop. THis means the username is the variable part of the save string. How do I insert this into the path string ? -- PSM |
#2
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Username in path
Copy/Paste the code below into a Module (click Insert/Module from the VB
editor's menu bar). Then calling the GetDesktopPath function will return the path to the user's desktop (no matter which operating system they are using). Note... the returned path will not have a trailing backspace at the end, so if you are concatenating this path with a filename, don't forget to add the backspace into the concatenation somewhere. '*************** START OF CODE *************** Private Declare Function SHGetFolderPath Lib "shfolder" _ Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, _ ByVal nFolder As Long, ByVal hToken As Long, _ ByVal dwFlags As Long, ByVal pszPath As String) As Long Private Const CSIDL_DESKTOPDIRECTORY As Long = &H10 Function GetDesktopPath() As String Dim strPath As String Dim lngReturn As Long strPath = String(255, 0) lngReturn = SHGetFolderPath(0, CSIDL_DESKTOPDIRECTORY, 0, 0, strPath) GetDesktopPath = Left$(strPath, InStr(1, strPath, Chr(0)) - 1) End Function '*************** END OF CODE *************** -- Rick (MVP - Excel) "PSM" wrote in message ... I want to create a button to save the file to the user desktop. THis means the username is the variable part of the save string. How do I insert this into the path string ? -- PSM |
#3
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Username in path
"Rick Rothstein" wrote...
.... '*************** START OF CODE *************** Private Declare Function SHGetFolderPath Lib "shfolder" _ * * * * Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, _ * * * * ByVal nFolder As Long, ByVal hToken As Long, _ * * * * ByVal dwFlags As Long, ByVal pszPath As String) As Long Private Const CSIDL_DESKTOPDIRECTORY As Long = &H10 Function GetDesktopPath() As String * Dim strPath As String * Dim lngReturn *As Long * strPath = String(255, 0) * lngReturn = SHGetFolderPath(0, CSIDL_DESKTOPDIRECTORY, 0, 0, strPath) * GetDesktopPath = Left$(strPath, InStr(1, strPath, Chr(0)) - 1) End Function '*************** END OF CODE *************** .... This works, but Function foo() As String foo = Environ("USERPROFILE") & "\Desktop" End Function is arguably easier to understand and maintain. Granted users outside environments governed by group policies could edit their Windows registry to change their desktop folder from the default Desktop subdir within their profile dir, so the simpler approach could return the wrong result. That said, I personally REALLY, REALLY HATE any application dropping anything on my desktop. User's My Documents directory would usually be a better place IF users' local folders were automatically backed up. If not, better to save the files into users' file server home directories which presumably are backed up automatically as part of their file servers' automatic backup. If necessary, put shortcuts to these files on users' desktops. |
#4
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Username in path
Interesting... here you are advocating using a method that might not be
guaranteed to work because it is simpler whereas in the "Isolate text in a long url" thread you are advancing what appears to be an opposite position. By the way, I completely agree with you on being against programs that drop files on one's Desktop... my defense is that I was just answering the question that was asked.<g -- Rick (MVP - Excel) "Harlan Grove" wrote in message ... "Rick Rothstein" wrote... .... '*************** START OF CODE *************** Private Declare Function SHGetFolderPath Lib "shfolder" _ Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, _ ByVal nFolder As Long, ByVal hToken As Long, _ ByVal dwFlags As Long, ByVal pszPath As String) As Long Private Const CSIDL_DESKTOPDIRECTORY As Long = &H10 Function GetDesktopPath() As String Dim strPath As String Dim lngReturn As Long strPath = String(255, 0) lngReturn = SHGetFolderPath(0, CSIDL_DESKTOPDIRECTORY, 0, 0, strPath) GetDesktopPath = Left$(strPath, InStr(1, strPath, Chr(0)) - 1) End Function '*************** END OF CODE *************** .... This works, but Function foo() As String foo = Environ("USERPROFILE") & "\Desktop" End Function is arguably easier to understand and maintain. Granted users outside environments governed by group policies could edit their Windows registry to change their desktop folder from the default Desktop subdir within their profile dir, so the simpler approach could return the wrong result. That said, I personally REALLY, REALLY HATE any application dropping anything on my desktop. User's My Documents directory would usually be a better place IF users' local folders were automatically backed up. If not, better to save the files into users' file server home directories which presumably are backed up automatically as part of their file servers' automatic backup. If necessary, put shortcuts to these files on users' desktops. |
#5
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
Username in path
"Rick Rothstein" wrote...
Interesting... here you are advocating using a method that might not be guaranteed to work because it is simpler whereas in the "Isolate text in a long url" thread you are advancing what appears to be an opposite position. Who says I need to be consistent? In corporate and governmental computing environments group policies generally inhibit or actually prevent users from changing this sort of basic configuration. So the odds are that my simplified approach in this thread would almost always work. OTOH, unless the OP in the other thread were parsing urls generated by his own company's web or intranet server, s/he has no control over the possible urls s/he needs to process. The odd there no longer favor simple approaches. On a statistical basis, I'll claim my trade-off between simplicity and robustness beats yours. By the way, I completely agree with you on being against programs that drop files on one's Desktop... my defense is that I was just answering the question that was asked.<g The cost of free answers in newsgroups is free advice. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
(username v1) | Excel Discussion (Misc queries) | |||
Formula too long - new file path is shorter than old file path - Excel 2003 | Excel Worksheet Functions | |||
hyperlink navigation path path wrong in Excel 2003 | Excel Discussion (Misc queries) | |||
how to change absolute path to relative path | Excel Worksheet Functions | |||
NT Username | Excel Discussion (Misc queries) |