Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"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. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"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. |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Inserting File name and path in Excel 2007 Documents | Excel Discussion (Misc queries) | |||
User wants to see full path in recent documents Excel 2007 | Excel Discussion (Misc queries) | |||
How can I automatically print file path on documents | Excel Discussion (Misc queries) | |||
How to path to user's desktop | Excel Programming | |||
Can't See Path to Recently Used Documents in Excel 2000 | Excel Discussion (Misc queries) |