Browse File Dialog in Excel VBA
In Excel file, if you are doing any folder operations or trying to read content from another text,xlsx, csv file. It is better to use this file dialog box rather than manually typing the file name with path.
It would reduce the typing errors and also the file path will be exact as how it is in the system.
Lets see how to invoke it from a VBA code and get the file path directly.File Open dialog in Excel VBAVisual Basic1234567891011121314151617181920212223Sub Choose_File()Dim sSh As WorksheetDim filedialog As Office.FileDialog, txtFileNameSet filedialog = Application.FileDialog(msoFileDialogFilePicker)Set sSh = ThisWorkbook.Sheets("Settings")txtFileName = ""With filedialog.AllowMultiSelect = False.Title = "Choose File(s)".Filters.Add "Excel", "*.xls*".Filters.Add "Csv", "*.csv*".Filters.Add "Text", "*.txt*".Filters.Add "All", "*.*"If .Show = True ThentxtFileName = .SelectedItems(1)End IfEnd WithsSh.Cells(1, 2) = txtFileNamesSh.Columns("B:B").AutoFitEnd Sub
Rename the sheet name from “Settings” to any worksheet name as it is in your Excel workbook.
VBA File Open Dialog Box
- Block Apps in FaceBook print screen Excel Countif Record Macro Timer in Excel Task Manager VCF HTML Table Import Data Thumbnails Text to Speech TTS Candy Crush C++ Programing Machine learning AI bulk email Excel VBA vba color index vba color codes Android social media Twitter Google+ Google Adsense Tips bitcoin Calendar in Excel outlook vba mass email Data Mining Excel Macro Facebook WhatsApp Wordpress python