View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Two File Dialogs

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.

"Alan" wrote:

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