Two File Dialogs

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
 
J

Joel

This is only one of th emacros in your workbook. there is probably another
macro that is causing the dialog to open twice. I would step through the
code to find where the dialog is opening twice or post more of the code.

Tto A break point click on line below and then press F9

If .Show = 0 Then Exit Sub

This is the line that displays the dialog. Then press F5 to continue. If
the dialog opens before reaching this line or after then there is another
place in the code that opens the dialog. If it reaches this statemnt twice
then something is causing this routine to run twice.

You can use F8 to step through the code after reaching a break point. Or
set more than one break point using F8 to find the trouble.
 
A

Alan

The problem turned out to be software gremlins. When I opened the
file tonight, the subroutine I posted was no longer there. I
recreated it exactly as before, and it works.

Go figure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top