I have a folder picker sub using the msoFileDialogFolderPicker. I trigger it based on a button click even in a userform. I pass the file path to a caption control within the browseFolderPath routine. Label4.Caption = strFilePath is the line of code. This occurs in the sub itself
I want to have this sub triggered by the click events of multiple other buttons and be able to store the individual file paths to individual caption controls associated with each button. How do I pass the file path that results from each pass of this routine back to the individual button click events?
I want to have this sub triggered by the click events of multiple other buttons and be able to store the individual file paths to individual caption controls associated with each button. How do I pass the file path that results from each pass of this routine back to the individual button click events?
VBA Code:
Private Sub CommandButton3_Click()
browseFolderPath
End Sub
VBA Code:
Sub browseFolderPath()
On Error GoTo err
Dim fileExplorer As FileDialog
Dim strFilePath As String
Set fileExplorer = Application.FileDialog(msoFileDialogFolderPicker)
'To allow or disable to multi select
fileExplorer.AllowMultiSelect = False
With fileExplorer
If .Show = -1 Then 'Any folder is selected
strFilePath = .SelectedItems.item(1)
Else ' else dialog is cancelled
MsgBox "You have cancelled the dialogue"
strFilePath = "" ' when cancelled set blank as file path.
End If
Label4.Caption = strFilePath
End With
err:
Exit Sub
End Sub