helpneeded2
Board Regular
- Joined
- Jun 25, 2021
- Messages
- 110
- Office Version
- 365
- Platform
- Windows
I am quite new to VBA and have tried a couple different examples for using VBA to open a file that is select via the file dialog box.
After I select the file, nothing happens -- the file does not open.
I can only guess that perhaps the code examples I have been looking at are old, and maybe there is newer code I need to use?
Here is the current code I am trying to use:
After I select the file, nothing happens -- the file does not open.
I can only guess that perhaps the code examples I have been looking at are old, and maybe there is newer code I need to use?
Here is the current code I am trying to use:
VBA Code:
Sub FileOpenDialogBox()
'Display a Dialog Box that allows to select a single file.
'The path for the file picked will be stored in fullpath variable
With Application.FileDialog(msoFileDialogFilePicker)
'Makes sure the user can select only one file
.AllowMultiSelect = False
'Filter to just the following types of files to narrow down selection options
.Filters.Add "Excel Files", "*.xlsx; *.xlsm; *.xls; *.xlsb", 1
'Show the dialog box
.Show
'Store in fullpath variable
fullpath = .SelectedItems.Item(1)
End With
'It's a good idea to still check if the file type selected is accurate.
'Quit the procedure if the user didn't select the type of file we need.
If InStr(fullpath, ".xls") = 0 Then
Exit Sub
End If
'Open the file selected by the user
Workbooks.Open fullpath
End Sub