Browse folders and input folder path in text box

mikey2322

Board Regular
Joined
May 10, 2006
Messages
59
Hi,

I have a text box in a form in which the person using the workbook inputs the destination folder of the files the worbook will produce when another macro is run. .

I have it so that you can type in the desired folder path (i.e. C:\Test\Test\...etc.) and it works but I also wanted to put a browse button beside the text box that would allow the user to browse and select the folder (i.e. ....Test\) and then hit ok and the folder path will show in the text box before the user hits the final button that will produce the files to be saved to that folder. Any help would be greatly appreciated!

Cheers,

Mike
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Mike

Lets say you add a standard Command Button the code might look something like

Code:
Private Sub CommandButton1_Click()
Dim a As String
a = Application.GetOpenFilename
Sheet1.Range("A1").Value = a
End Sub

Just change the Sheet1.Range("A1").Value to the syntax for your textbox

HTH


Dave
 
Upvote 0
Hi David,

Thanks for that bit of code, it does what I want except it makes me choose a file as the end of the path where I just want to choose the folder is there a way of changing it to FileOpenFolder etc.??

Cheers,

Mike
 
Upvote 0
Hi Mike

Not something I know myself but a quick search turned this up

Hope it helps

Dave ;)
 
Upvote 0
From here:
Code:
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

'API declarations
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

Here let us use the above shell functions to open the browse directory dialog

Sub Show_BrowseDirectory_Dialog()

' BrowseForFolder
' SHBrowseForFolder API Function Example

Dim dirInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer

' Set Default Root folder = Desktop
dirInfo.pidlRoot = 0&

dirInfo.lpszTitle = "Browse directory!"

' Type of directory
dirInfo.ulFlags = &H1

' Show the Browse Dialog
x = SHBrowseForFolder(dirInfo)

' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
MsgBox "You have selected :=" & Left(path, pos - 1)
Else
MsgBox "Browse a Directory..."
Show_BrowseDirectory_Dialog
End If

End Sub
 
Upvote 0
Works on XL2002 and later versions

Code:
Dim FolderName As String
With Application.FileDialog(msoFileDialogFolderPicker)
    .Show
    FolderName = .SelectedItems(1)
End With
 
Upvote 0

Forum statistics

Threads
1,203,615
Messages
6,056,307
Members
444,858
Latest member
ucbphd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top