Hello
it's okay I found a solution!!
After multiple attempts, I'll leave you the code
The solutions for these two positions:
http://codes-sources.commentcamarche.net/forum/affich-15102-selectionner-un-repertoire-avec-une-boite-de-dialogue-en-vba
http://www.cadsharp.com/blog/solidworks-macro-compatible-64-vba7/
to be modified as you wish:
Private Type BROWSEINFO ' used by the function GetFolderName
hOwner As LongPtr
pidlRoot As LongPtr
pszDisplayName As String
lpszTitle As String
ulFlags As LongPtr
lpfn As LongPtr
lParam as LongPtr
iImage As LongPtr
End Type
#If VBA7 Then
Private Declare PtrSafe Function SHGetPathFromIDList Lib "shell32.dll" aka "SHGetPathFromIDListA" (ByVal pidl as LongPtr, ByVal pszPath as String) as LongPtr
Private Declare PtrSafe Function SHBrowseForFolder Lib "shell32.dll" aka "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPtr
#Else
'Private Declare Function SHGetPathFromIDList lib "shell32.dll" aka "SHGetPathFromIDListA" (ByVal pidl as LongPtr, ByVal pszPath as String) as long
'Private Declare Function SHBrowseForFolder Lib "shell32.dll" aka "SHBrowseForFolderA" (lpBrowseInfo as BROWSEINFO) as long
#End Yew
Function GetFolderName(Msg As String) As String
' returns the name of the folder selected by the user
Dim bInfo As BROWSEINFO, path As String, r As LongPtr, x As LongPtr, pos As Integer
'bInfo.pidlRoot 0& ' Root folder Desktop
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a working directory" ' the dialog title
Else
bInfo.lpszTitle = Msg ' the dialog title
End If
bInfo.ulFlags = &H1 ' Type of directory to return
x = SHBrowseForFolder(bInfo) ' display the dialog
' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetFolderName = Left(path, pos - 1)
Else
GetFolderName = ""
End If
End Function
Private Sub CommandButton2_Click()
Dim Rep0 As String
Rep0 = GetFolderName("Choose a working directory")
FrmE2S.TextBox1.Text = Rep0
End Sub