#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default 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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,231
Default 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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default 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   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,231
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
(username v1) JJernigan Excel Discussion (Misc queries) 0 June 12th 08 09:13 PM
Formula too long - new file path is shorter than old file path - Excel 2003 Greg J Excel Worksheet Functions 1 November 22nd 06 05:16 PM
hyperlink navigation path path wrong in Excel 2003 CE Admin Excel Discussion (Misc queries) 5 January 7th 06 07:47 PM
how to change absolute path to relative path hwijgerse Excel Worksheet Functions 0 November 25th 05 07:18 AM
NT Username ceemo Excel Discussion (Misc queries) 4 August 2nd 05 04:39 PM


All times are GMT +1. The time now is 02:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"