GetOpenFilename multiselect

Emily

Active Member
Joined
Aug 28, 2002
Messages
304
The code below does not work when the first With is marked as remark, any idea?

Thanks
Emily

Code:
Sub DisplayFiles()

    Dim FileNames As Variant
    Dim i  As Integer
    'With Application
    '    .DisplayAlerts = False
    '    .EnableEvents = False
    '    .ScreenUpdating = False
    'End With
    
    FileNames = Application.GetOpenFilename("Excel Files,*.xls", , , , True)
        
    If IsArray(FileNames) Then
        For i = LBound(FileNames) To UBound(FileNames)
             MsgBox FileNames(i)
        Next i
    End If
    With Application
        .DisplayAlerts = True
        .EnableEvents = True
        .ScreenUpdating = True
    End With

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Not sure quite what the problem is, but this seems to work fine-

Code:
Sub DisplayFiles()
    Dim FileNames As Variant
    Dim i  As Integer
    
    With Application
        .DisplayAlerts = False
        .EnableEvents = False
        .ScreenUpdating = False
        
        FileNames = .GetOpenFilename("Excel Files,*.xls", , , , True)
        
        If IsArray(FileNames) Then
            For i = LBound(FileNames) To UBound(FileNames)
             MsgBox FileNames(i)
            Next i
        End If
    
        .DisplayAlerts = True
        .EnableEvents = True
        .ScreenUpdating = True
    End With

End Sub
 
Upvote 0
Emily

Works for me with or without the first With being commented out.

I'm running Excel 2000 on Windows 98.

What is the actual problem you are having?

Are you actually using this code to work with the files selected?
 
Upvote 0
It cannot show message box twice when 2 files were selected. It works fine when the comment are removed

I am running on Chinese Window WinMe + Office Xp
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,695
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top