I'm completely new to VBA for applications and I have some pretty basic questions. I'm creating a userform and I need to be able to exit one of the subs early. I simply don't want to get a debug error when I exit GetOpenFilename window without selecting any workbooks and just end the sub. Secondly, I can't get GetOpenFilename dialogue box to show all the other available filenames (xls, xlm, xlsx, xlsm) when "All Files" filter is selected. What should I change for this to work properly?
I've tried to exit sub when TempArray IsEmpty, but for some reason it doesn't work.
Private Sub cmdAddWorkbooks_Click()
'Variables declarations
Dim FileFilter As String
Dim FilterIndex As Long
Dim Title As String
Dim MultiSelect As Boolean
Dim WorkbookCounter As Long
Dim TempArray() As Variant
Dim SelectedWorkbooksTemp() As Variant
ReDim SelectedWorkbooksTemp(0 To 1, 0 To 1)
'Setting up GetOpenFilename parameteres
FileFilter = "Microsoft Excel Worksheet (*.xlsx),*xlsx," & _
"Microsoft Excel Worksheet with Macros (*.xlsm),*xlsm," & _
"Microsoft Excel 97-2003 Worksheet (*.xls),*xls," & _
"Microsoft Excel 97-2003 Worksheet with Macros (*.xlm),*xlm," & _
"All Files (.),."
FilterIndex = 5
Title = "Select Workbooks"
MultiSelect = True
'Using GetOpenFilename
On Error Resume Next
TempArray = Application.GetOpenFilename _
(FileFilter:=FileFilter, _
FilterIndex:=FilterIndex, _
Title:=Title, _
MultiSelect:=MultiSelect)
'exiting doesnt work
On Error GoTo 0
If IsEmpty(TempArray) Then End Sub
WorkbookCounter = UBound(TempArray)
ReDim SelectedWorkbooksTemp(1 To WorkbookCounter, 1 To WorkbookCounter)
For i = 1 To WorkbookCounter
SelectedWorkbooksTemp(i, 1) = TempArray(i)
SelectedWorkbooksTemp(i, 2) = Dir(TempArray(i))
Next i
End Sub