I use this code here:
Code:
Private Function GETDIR()
Dim mybrowse As BROWSEINFO
Dim Mydirectory As String
Dim path As String
Dim R As Long, X As Long, pos As Integer
mybrowse.pidlRoot = 0&
'************************************************************************************************
'0 'Desktop is the root directory. With BIF_returnonlyfsdirs circumvents problem with OK-button *
'1 'Internet Explorer is the root *
'2 'Programs folder of the start menu is the root *
'3 'Control Panel is the root. Needs BIF_browseincludefiles *
'4 'Printers folder is the root. Needs BIF_browseincludefiles *
'5 'Documentsfolder is the root *
'6 'Favorites is the root *
'7 'Startup-folder of the startmenu is the root. Needs BIF_browseincludefiles *
'8 'Recentfolder is the root. Needs BIF_browseincludefiles *
'9 'Sendto-folder is the root. Needs BIF_browseincludefiles *
'10 'Recycle Bin is the root. Needs BIF_browseincludefiles *
'11 'Start Menu is the root *
'16 'The Desktopdirectory is the root directory *
'17 'The drives (My computer) folder is the root *
'18 'The networkneighbourhood is the root *
'19 'The nethoodfolder is the root *
'20 'The fontsfolder is the root *
'21 'The templatesfolder is the root *
'************************************************************************************************
mybrowse.lpszTitle = "SELECT A DIRECTORY"
mybrowse.ulFlags = &H1 '(H4000 RETURNS FILENAME)
X = SHBrowseForFolder(mybrowse)
path = Space$(512)
R = SHGetPathFromIDList(ByVal X, ByVal path)
If R Then
pos = InStr(path, Chr$(0))
Mydirectory = Left(path, pos - 1)
Me.txtoutputdirectory.value = Mydirectory
End If
End Function
Me.txtoutputdirectory.value = Mydirectory
Puts the value in the text box. I called my text box txtoutputdirectory
Then on the button, run a command.
Hope this helps,