OVH Cloud OVH Cloud

Modif de fonction

4 réponses
Avatar
David
Bonjour à tous

Débutant +++
Excel 2000 - Windows XP


J'ai cette fonction qui viens de ??? (merci à lui) j'aimerais quelle
m'affiche le résultat dans la cellule A1 et non pas dans une boite de
dialogue.

Comment faire ?

Merci de votre aide

Option Explicit

Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type


Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As
String) As Long

Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Sub Recherche()
MsgBox GetDirectory
End Sub

Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer

bInfo.pidlRoot = 19&

If IsMissing(Msg) Then
bInfo.lpszTitle = "Selectionnez un dossier."
Else
bInfo.lpszTitle = Msg
End If

'Type de renvoi : dossier
bInfo.ulFlags = &H1
'Type de renvoi : fichier
'bInfo.ulFlags = &H4000

x = SHBrowseForFolder(bInfo)

path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function

4 réponses

Avatar
poypoy
Bonjour David,

j'avoue ne pas comprendre la moitié de ta macro (et je n'ai pas le courage
de la tester ) mais je sais répondre à ta question ^^ :

Tu remplace
Sub Recherche()
MsgBox GetDirectory
End Sub

p

Bonjour à tous

Débutant +++
Excel 2000 - Windows XP


J'ai cette fonction qui viens de ??? (merci à lui) j'aimerais quelle
m'affiche le résultat dans la cellule A1 et non pas dans une boite de
dialogue.

Comment faire ?

Merci de votre aide

Option Explicit

Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type


Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As
String) As Long

Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Sub Recherche()
MsgBox GetDirectory
End Sub

Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer

bInfo.pidlRoot = 19&

If IsMissing(Msg) Then
bInfo.lpszTitle = "Selectionnez un dossier."
Else
bInfo.lpszTitle = Msg
End If

'Type de renvoi : dossier
bInfo.ulFlags = &H1
'Type de renvoi : fichier
'bInfo.ulFlags = &H4000

x = SHBrowseForFolder(bInfo)

path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function






Avatar
poypoy
Dsl tromper de bouton,
donc tu le remplace par
sub recherche()
range("a1") = getdirectory
end sub

Cordialement
Benjamin

Bonjour à tous

Débutant +++
Excel 2000 - Windows XP


J'ai cette fonction qui viens de ??? (merci à lui) j'aimerais quelle
m'affiche le résultat dans la cellule A1 et non pas dans une boite de
dialogue.

Comment faire ?

Merci de votre aide

Option Explicit

Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type


Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As
String) As Long

Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Sub Recherche()
MsgBox GetDirectory
End Sub

Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer

bInfo.pidlRoot = 19&

If IsMissing(Msg) Then
bInfo.lpszTitle = "Selectionnez un dossier."
Else
bInfo.lpszTitle = Msg
End If

'Type de renvoi : dossier
bInfo.ulFlags = &H1
'Type de renvoi : fichier
'bInfo.ulFlags = &H4000

x = SHBrowseForFolder(bInfo)

path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function






Avatar
David
Ben le principal c'est que cela fonctionne !!!

merci beaucoup

Bonne journée
Avatar
poy-poy
Lol David

C'est sur que c'est pas comme ca que tu sauras le faire la prochaine fois,
mais c'est vrai que c'est bien utile ^^

Bonne journée itou
Benjamin


Ben le principal c'est que cela fonctionne !!!

merci beaucoup

Bonne journée