Hi all, I have a VBA function that pops up a folder dialog where the user selects a folder. Now I need that folder name (full path) to be written into a certain cell, but the code I've created for that doesn't work. Hope someone could help me out!
Below are the function and the code. The code is supposed to pop up the browse dialog only if the existing cell value doesn't return a correct folder.
Function BrowseFolder(Title As String, _
Optional InitialFolder As String = vbNullString, _
Optional InitialView As Office.MsoFileDialogView = _
msoFileDialogViewList) As String
Dim V As Variant
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = Title
.Show
End With
BrowseFolder = CStr(V)
End Function
Sub Folder_Picker()
Dim FolderPath As String
FolderPath = Worksheets("Abc").Cells(3, 7).Value & "\"
If Dir(FolderPath & "*.xlsx") = "" Then
Sheets("Abc").Select
Cells(3, 7).Value = BrowseFolder("Please select the folder")
End If
End Sub
Bookmarks