This is the same dialog for selecting a file OR folder in VBA

I have an Excel workbook that needs to be filled with file or folder paths in order to process them later. What I would like to do is to use the same dialog to select the paths you want, for example if a file is selected, return its path, but if no file is selected, return the current folder path. Can this be done relatively easily? Or do I need to invite the user, does he want a file or folder before loading the viewport?

I can create a file viewer dialog like:   Application.FileDialog(msoFileDialogFilePicker)

Or folder browse dialog:   Application.FileDialog(msoFileDialogFolderPicker)

But how can I combine the two of them? It is not necessary to use Application.FileDialog if there is a better option. Thanks everyone!

+3


source to share


1 answer


I would create a custom form with just an input field and when the user clicks on it, call the filedialog field and fill it with output. However, if the user doesn't click on it and just clicks OK, then handle if textbox = "" even with your default location. This required knowledge of custom forms.



+1


source







All Articles