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 SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
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