Here is a nice and simple one for you
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal Hwnd As Long, ByVal nIndex As Long, ByVal wNewLong As Long) As Long
Private Declare PtrSafe Function apiShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" _
(ByVal Hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
As Long
''Globale variable for DIR Browser
Private 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
Private Const BIF_NEWDIALOGSTYLE = &H40
' show edit box
Private Const BIF_EDITBOX = &H10&
'Private Const BIF_BROWSEINCLUDEFILES = &H4000
'Private Const BIF_RETURNONLYFSDIRS = &H1
'Private Const MAX_PATH = 260
Private Const BIF_RETURNONLYFSDIRS As Long = &H1
Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
Private Const BIF_RETURNFSANCESTORS As Long = &H8
Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
Private Const BIF_BROWSEFORPRINTER As Long = &H2000
Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000
Private Const MAX_PATH As Long = 260
'***App Window Constants***
Private Const WIN_NORMAL = 1 'Open Normal
Private Const WIN_MAX = 3 'Open Maximized
Private Const WIN_MIN = 2 'Open Minimized
'***Error Codes***
Private Const ERROR_SUCCESS = 32&
Private Const ERROR_NO_ASSOC = 31&
Private Const ERROR_OUT_OF_MEM = 0&
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&
Private Const ERROR_BAD_FORMAT = 11&
Private Function BrowseFolder(Optional Caption As String, _
Optional InitialFolder As String) As String
Dim sh As Shell32.Shell
Dim f As Shell32.Folder
Set sh = New Shell32.Shell
Set f = sh.BrowseForFolder(0&, Caption, BIF_RETURNONLYFSDIRS, InitialFolder)
If Not f Is Nothing Then
BrowseFolder = f.items.Item.path
End If
End Function
Function ShowFolderDialog() As String
Dim InitFolder As String
InitFolder = "C:/"
Dim BrowserCaption As String
BrowserCaption = "Browse for Output Folder"
Dim FName As String
FName = BrowseFolder(Caption:=BrowserCaption, InitialFolder:=InitFolder)
If FName = vbNullString Then
Exit Sub
Else
ShowFolderDialog = FName & "\"
End If
End Function
Giving a Browse Folder Dialog like this:

To use, you need something like this:
Me.MyTextbox.Value = ShowFolderDialog
You could also change the function slightly to pass the path you want to use dynamically so that you can reuse the same code for different places:
Function ShowFolderDialog(StartPath As String) As String
Dim BrowserCaption As String
BrowserCaption = "Browse for Output Folder"
Dim FName As String
FName = BrowseFolder(Caption:=BrowserCaption, InitialFolder:=StartPath)
If FName = vbNullString Then
Exit Sub
Else
ShowFolderDialog = FName & "\"
End If
End Function
You would then use it like this:
ShowFolderDialog("\\MyNetworkPath")
or
Dim UserName As String
UserName = (Environ$("Username"))
ShowFolderDialog("C:\Users\" & UserName & "\Documents")
etc etc
Hope that helps. The more code you have, the more memory used 😉
Nacho
Nacho
Automation & Design Engineer
Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.