Share via


How to: Display a Dialog Box to Open Excel Files

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2003

  • Excel 2007

For more information, see Features Available by Application and Project Type.

The following code prompts users to open a new workbook in Microsoft Office Excel. It sets properties to allow multi-selection, clears the list of available filters, and adds two new filters. The code then calls the Execute method of the FileDialog object to open the requested files.

Example

With Me.Application.FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogOpen)

    .AllowMultiSelect = True
    .Filters.Clear()
    .Filters.Add("Excel Files", "*.xls;*.xlw")
    .Filters.Add("All Files", "*.*")

    If .Show = True Then
        .Execute()
    End If 
End With
Microsoft.Office.Core.FileDialog fd = 
    this.Application.get_FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogOpen);

fd.AllowMultiSelect = true; 
fd.Filters.Clear(); 
fd.Filters.Add("Excel Files", "*.xls;*.xlw", missing); 
fd.Filters.Add("All Files", "*.*", missing); 

if (fd.Show() != 0)
{
    fd.Execute();
}

See Also

Tasks

How to: List Recently Used Workbook Files

How to: Open Workbooks

How to: Activate Workbooks

Concepts

Working with Workbooks

The Variable missing and Optional Parameters in Office Solutions