nours2001
Messages postés7Date d'inscriptionlundi 4 février 2002StatutMembreDernière intervention16 avril 2003
-
12 août 2002 à 14:57
cs_titicar
Messages postés181Date d'inscriptionjeudi 30 mai 2002StatutMembreDernière intervention19 août 2012
-
19 août 2002 à 12:13
Bonjour:
Dans un developpement VBA, j'aurais besoin de pouvoir connaitre le chemin vers le repertoire "mes documents" de l'utilisateur.
pour pouvoir sauvegarder auomatiquement un fichier.
J'ai trouvé pas mal d'exemples pour trouver le chemin vers les repertoires "windows", "sytem" et "temp", mais je n'arrive pas à trouver comment faire pour récupérer le chemin vers "mes documents"
nours2001
Messages postés7Date d'inscriptionlundi 4 février 2002StatutMembreDernière intervention16 avril 2003 13 août 2002 à 09:31
Merci beaucoup,
Ceci est déjà pas mal...
Malheureusement, sur certains postes, il se pourrais que le dossiers "Mes Documents" ai été déplacé...
Ceci marche très bien sur un poste NT ou 2000. Mais cela donne quoi sur un poste en WIN 98???
Je n'ai pas d'OS de ce type pour vérifier.
cs_titicar
Messages postés181Date d'inscriptionjeudi 30 mai 2002StatutMembreDernière intervention19 août 2012 19 août 2002 à 12:13
Salut,
Essaie l'API suivante.
Elle marche en VB, mais jamais testée en VBA:
'-------------------------------------
'Répertoires créés par Windows
Private Type SHITEMID
cb As Long
abID As Byte
End Type
Private Type ITEMIDLIST
mkid As SHITEMID
End Type
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long
Private Const NOERROR = 0
Const WinPath_Bureau = 0
Const WinPath_Programmes = 2
Const WinPath_Mes_Documents = 5
Const WinPath_Favoris = 6
Const WinPath_Demarrage = 7
Const WinPath_Fichiers_recents = 8
Const WinPath_Envoyer_vers = 9
Const WinPath_Menu_Demarrer = 11
Const WinPath_Polices = 20
Const WinPath_ShellNew = 21
Const WinPath_Fichiers_temporaires_Internet = 32
Const WinPath_Cookies = 33
Const WinPath_Historique = 34
Function WinPath(Num As Integer) As String
Dim r As Long
Dim path As String
Dim IDL As ITEMIDLIST
Dim Csid As Long
CSIDL = CLng(Num)
r = SHGetSpecialFolderLocation(Form1.hWnd, CSIDL, IDL)
If r = NOERROR Then
path$ = Space$(512)
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal path$)
WinPath = Left$(path, InStr(path, Chr$(0)) - 1)
Exit Function
End If
End Function
Function GetDirectory_Mes_Documents() As String
GetDirectory_Mes_Documents = WinPath(WinPath_Mes_Documents)
End Function
'----------------------------------------------------
SEUL HIC : dans la Sub WinPath, tu dois donner le nom de ta Form!