Your choice of a sub folder from the desktop makes the coding required to
obtain the true path rather more complicated, but after doing some digging
on the web, the following does the trick:
Option Explicit
Private Const CSIDL_DESKTOP = &H0
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
Private Function GetSpecialfolder(CSIDL As Long) As String
Dim r As Long, Path$
Dim IDL As ITEMIDLIST
'Get the special folder
r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
If r = 0 Then
'Create a buffer
Path$ = Space$(512)
'Get the path from the IDList
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
'Remove the unnecessary chr$(0)'s
GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
Exit Function
End If
GetSpecialfolder = ""
End Function
Sub Test()
Word.Documents.Open (GetSpecialfolder(CSIDL_DESKTOP) & "\parade\yearly.doc")
Word.Documents.Open (GetSpecialfolder(CSIDL_DESKTOP) &
"\parade\yearlya.doc")
End Sub
I take no credit for the producing the code.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>