0 out of 2 rated this helpful - Rate this topic

How to: Display a Dialog Box to Open Excel Files

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.

Applies to: The information in this topic applies to document-level projects and application-level projects for Excel 2007 and Excel 2010. For more information, see Features Available by Office Application and Project Type.


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();
}


Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
How to get the full default Excel read filters
Omit
fd.Filters.Clear(); 
fd.Filters.Add("Excel Files", "*.xls;*.xlw", missing); 
fd.Filters.Add("All Files", "*.*", missing);

to use the complete normal Excel Filter set for all the files Excel can open.