A
Alan
For some reason, the code below displays the file dialog twice in
a row. It shows the dialog, the user selects files, it shows the
dialog again, the user selects files, and then it writes the second
set of selections to a worksheet.
I do not understand why it displays the dialog twice. I would
appreciate any pointers.
Thanks, Alan
Sub SelectDocuments()
Const OutputFileCaption As String = _
"Please select one or more Word documents"
Dim dialog As FileDialog
Dim FileFilter As FileDialogFilters
Dim NumFiles As Integer, i As Integer
Set WBmain = GetActiveWB
Set ConfigWS = CreateConfigWS(WBmain)
ConfigWS.Activate
ConfigWS.Visible = xlSheetVisible
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
With dialog
Set FileFilter = .Filters
FileFilter.Clear
FileFilter.Add "Word documents", "*.doc, *.docx"
.AllowMultiSelect = True
If .Show = 0 Then Exit Sub
NumFiles = .SelectedItems.Count
If .SelectedItems.Count > 0 Then
For i = 1 To NumFiles
ConfigWS.Cells(i + 1, 2).Value = .SelectedItems.Item(i)
Next i
End If
End With
End Sub
a row. It shows the dialog, the user selects files, it shows the
dialog again, the user selects files, and then it writes the second
set of selections to a worksheet.
I do not understand why it displays the dialog twice. I would
appreciate any pointers.
Thanks, Alan
Sub SelectDocuments()
Const OutputFileCaption As String = _
"Please select one or more Word documents"
Dim dialog As FileDialog
Dim FileFilter As FileDialogFilters
Dim NumFiles As Integer, i As Integer
Set WBmain = GetActiveWB
Set ConfigWS = CreateConfigWS(WBmain)
ConfigWS.Activate
ConfigWS.Visible = xlSheetVisible
Set dialog = Application.FileDialog(msoFileDialogFilePicker)
With dialog
Set FileFilter = .Filters
FileFilter.Clear
FileFilter.Add "Word documents", "*.doc, *.docx"
.AllowMultiSelect = True
If .Show = 0 Then Exit Sub
NumFiles = .SelectedItems.Count
If .SelectedItems.Count > 0 Then
For i = 1 To NumFiles
ConfigWS.Cells(i + 1, 2).Value = .SelectedItems.Item(i)
Next i
End If
End With
End Sub