![]() |
Finding a user's My Documents path
Is there a way to find a user's complete path to the location of their My
Documents folder and assign that path to a variable called pname? For example, the complete path to my My Documents folder is: C:\Documents and Settings\bob\My Documents\ So I would want pname = C:\Documents and Settings\bob\My Documents\ Thanks in advance for any help. Bob |
Finding a user's My Documents path
maybe this
Sub test() Dim fPath As String fPath = "C:\Documents and Settings\" & Environ("username") & "\My Documents\" MsgBox fPath End Sub -- Gary "Bob" wrote in message ... Is there a way to find a user's complete path to the location of their My Documents folder and assign that path to a variable called pname? For example, the complete path to my My Documents folder is: C:\Documents and Settings\bob\My Documents\ So I would want pname = C:\Documents and Settings\bob\My Documents\ Thanks in advance for any help. Bob |
Finding a user's My Documents path
Chip also has information on his site:
http://www.cpearson.com/Excel/SpecialFolders.htm "Bob" wrote: Is there a way to find a user's complete path to the location of their My Documents folder and assign that path to a variable called pname? For example, the complete path to my My Documents folder is: C:\Documents and Settings\bob\My Documents\ So I would want pname = C:\Documents and Settings\bob\My Documents\ Thanks in advance for any help. Bob |
Finding a user's My Documents path
Gary,
Thanks for your help! I will give your code a try tomorrow. Bob "Gary Keramidas" wrote: maybe this Sub test() Dim fPath As String fPath = "C:\Documents and Settings\" & Environ("username") & "\My Documents\" MsgBox fPath End Sub -- Gary "Bob" wrote in message ... Is there a way to find a user's complete path to the location of their My Documents folder and assign that path to a variable called pname? For example, the complete path to my My Documents folder is: C:\Documents and Settings\bob\My Documents\ So I would want pname = C:\Documents and Settings\bob\My Documents\ Thanks in advance for any help. Bob |
Finding a user's My Documents path
Thanks for the link! The solution appears to be far more complex than what I
really need. However, I will retain the link for potential future use. Bob "JMB" wrote: Chip also has information on his site: http://www.cpearson.com/Excel/SpecialFolders.htm "Bob" wrote: Is there a way to find a user's complete path to the location of their My Documents folder and assign that path to a variable called pname? For example, the complete path to my My Documents folder is: C:\Documents and Settings\bob\My Documents\ So I would want pname = C:\Documents and Settings\bob\My Documents\ Thanks in advance for any help. Bob |
Finding a user's My Documents path
here' another way
fpath = environ("userprofile") & "\My Documents\" -- Gary "Bob" wrote in message ... Gary, Thanks for your help! I will give your code a try tomorrow. Bob "Gary Keramidas" wrote: maybe this Sub test() Dim fPath As String fPath = "C:\Documents and Settings\" & Environ("username") & "\My Documents\" MsgBox fPath End Sub -- Gary "Bob" wrote in message ... Is there a way to find a user's complete path to the location of their My Documents folder and assign that path to a variable called pname? For example, the complete path to my My Documents folder is: C:\Documents and Settings\bob\My Documents\ So I would want pname = C:\Documents and Settings\bob\My Documents\ Thanks in advance for any help. Bob |
Finding a user's My Documents path
Gary,
Thanks again! Bob "Gary Keramidas" wrote: here' another way fpath = environ("userprofile") & "\My Documents\" -- Gary "Bob" wrote in message ... Gary, Thanks for your help! I will give your code a try tomorrow. Bob "Gary Keramidas" wrote: maybe this Sub test() Dim fPath As String fPath = "C:\Documents and Settings\" & Environ("username") & "\My Documents\" MsgBox fPath End Sub -- Gary "Bob" wrote in message ... Is there a way to find a user's complete path to the location of their My Documents folder and assign that path to a variable called pname? For example, the complete path to my My Documents folder is: C:\Documents and Settings\bob\My Documents\ So I would want pname = C:\Documents and Settings\bob\My Documents\ Thanks in advance for any help. Bob |
Finding a user's My Documents path
"Gary Keramidas" <GKeramidasATmsn.com wrote...
here' another way fpath = environ("userprofile") & "\My Documents\" .... Not guaranteed to work when users change the name of their "My Documents" folder (which, FWLIW, I've done myself). And I believe it's no longer called "My Documents" in Vista, but I could be wrong about that. The only guaranteed correct way to determine a user's "My Documents" folder's drive/directory path is by going into the Windows Registry, in the HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\Shell Folders key, and finding the value of the Personal value-name. |
Finding a user's My Documents path
Hi,
Unless My Documents is moved to other path, this is a special folder, better you use API calls to get the correct path, see in www.oaltd.co.uk. -- Regards, Halim "Gary Keramidas" wrote: here' another way fpath = environ("userprofile") & "\My Documents\" -- Gary "Bob" wrote in message ... Gary, Thanks for your help! I will give your code a try tomorrow. Bob "Gary Keramidas" wrote: maybe this Sub test() Dim fPath As String fPath = "C:\Documents and Settings\" & Environ("username") & "\My Documents\" MsgBox fPath End Sub -- Gary "Bob" wrote in message ... Is there a way to find a user's complete path to the location of their My Documents folder and assign that path to a variable called pname? For example, the complete path to my My Documents folder is: C:\Documents and Settings\bob\My Documents\ So I would want pname = C:\Documents and Settings\bob\My Documents\ Thanks in advance for any help. Bob |
Finding a user's My Documents path
"My Documents" in Vista, but I could be wrong about that.
Correct C:\Users\Ron\Documents The OP can try this If I rename my folder to "DocumentsFromRon" the code will work for me Harlan to open the folder Sub GetSpecialFolder() 'Special folders are : AllUsersDesktop, AllUsersStartMenu 'AllUsersPrograms, AllUsersStartup, Desktop, Favorites 'Fonts, MyDocuments, NetHood, PrintHood, Programs, Recent 'SendTo, StartMenu, Startup, Templates Dim WshShell As Object Dim SpecialPath As String Set WshShell = CreateObject("WScript.Shell") SpecialPath = WshShell.SpecialFolders("MyDocuments") 'Open folder in Explorer Shell "explorer.exe " & SpecialPath, vbNormalFocus End Sub -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Harlan Grove" wrote in message ... "Gary Keramidas" <GKeramidasATmsn.com wrote... here' another way fpath = environ("userprofile") & "\My Documents\" ... Not guaranteed to work when users change the name of their "My Documents" folder (which, FWLIW, I've done myself). And I believe it's no longer called "My Documents" in Vista, but I could be wrong about that. The only guaranteed correct way to determine a user's "My Documents" folder's drive/directory path is by going into the Windows Registry, in the HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\Shell Folders key, and finding the value of the Personal value-name. |
Finding a user's My Documents path
Very simple way Ron,,, good way I think
-- Regards, Halim "Ron de Bruin" wrote: "My Documents" in Vista, but I could be wrong about that. Correct C:\Users\Ron\Documents The OP can try this If I rename my folder to "DocumentsFromRon" the code will work for me Harlan to open the folder Sub GetSpecialFolder() 'Special folders are : AllUsersDesktop, AllUsersStartMenu 'AllUsersPrograms, AllUsersStartup, Desktop, Favorites 'Fonts, MyDocuments, NetHood, PrintHood, Programs, Recent 'SendTo, StartMenu, Startup, Templates Dim WshShell As Object Dim SpecialPath As String Set WshShell = CreateObject("WScript.Shell") SpecialPath = WshShell.SpecialFolders("MyDocuments") 'Open folder in Explorer Shell "explorer.exe " & SpecialPath, vbNormalFocus End Sub -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Harlan Grove" wrote in message ... "Gary Keramidas" <GKeramidasATmsn.com wrote... here' another way fpath = environ("userprofile") & "\My Documents\" ... Not guaranteed to work when users change the name of their "My Documents" folder (which, FWLIW, I've done myself). And I believe it's no longer called "My Documents" in Vista, but I could be wrong about that. The only guaranteed correct way to determine a user's "My Documents" folder's drive/directory path is by going into the Windows Registry, in the HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\Shell Folders key, and finding the value of the Personal value-name. |
Finding a user's My Documents path
Unless My Documents is moved to other path, this is a special folder,
better you use API calls to get the correct path, see in www.oaltd.co.uk. Here is an API method to get the path to "My Documents" (called Documents now on Vista). I tried posting this same routine twice directly to one of the OP's messages and, while I got no bounce-back or error, neither message ever got posted there (at least I can't see them in my newsreader); so, I figured I would try again here as my code fits your comments... Copy the code below my signature into your code window and, for an example, call it this way... pname = GetMyDocumentsFolder() from within your own code. Better yet, add a Module to your project (Insert/Module from VBA's menu) and not only can you call it from within your own code, but you can call it from a worksheet just like a built-in function also. Rick Private Type ****EMID cb As Long abID As Byte End Type Private Type ITEMIDLIST mkid As ****EMID End Type Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _ (ByVal hwndOwner As Long, _ ByVal nFolder As Long, _ pidl As ITEMIDLIST) As Long Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _ Alias "SHGetPathFromIDListA" _ (ByVal pidl As Long, _ ByVal pszPath As String) As Long Function GetMyDocumentsFolder() As String Dim RetVal As Long Dim Path As String Dim IDL As ITEMIDLIST Const CSIDL_PERSONAL = &H5 If SHGetSpecialFolderLocation(0&, CSIDL_PERSONAL, IDL) = 0 Then Path = Space$(512) SHGetPathFromIDList IDL.mkid.cb, Path GetMyDocumentsFolder = Trim$(Replace(Path, Chr$(0), "")) End If End Function |
Finding a user's My Documents path
Ron,
Thanks for pointing out the caveats. I will be sure to use your code below. Thanks again, Bob "Ron de Bruin" wrote: "My Documents" in Vista, but I could be wrong about that. Correct C:\Users\Ron\Documents The OP can try this If I rename my folder to "DocumentsFromRon" the code will work for me Harlan to open the folder Sub GetSpecialFolder() 'Special folders are : AllUsersDesktop, AllUsersStartMenu 'AllUsersPrograms, AllUsersStartup, Desktop, Favorites 'Fonts, MyDocuments, NetHood, PrintHood, Programs, Recent 'SendTo, StartMenu, Startup, Templates Dim WshShell As Object Dim SpecialPath As String Set WshShell = CreateObject("WScript.Shell") SpecialPath = WshShell.SpecialFolders("MyDocuments") 'Open folder in Explorer Shell "explorer.exe " & SpecialPath, vbNormalFocus End Sub -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Harlan Grove" wrote in message ... "Gary Keramidas" <GKeramidasATmsn.com wrote... here' another way fpath = environ("userprofile") & "\My Documents\" ... Not guaranteed to work when users change the name of their "My Documents" folder (which, FWLIW, I've done myself). And I believe it's no longer called "My Documents" in Vista, but I could be wrong about that. The only guaranteed correct way to determine a user's "My Documents" folder's drive/directory path is by going into the Windows Registry, in the HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\Shell Folders key, and finding the value of the Personal value-name. |
All times are GMT +1. The time now is 08:49 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com