This documentation is archived and is not being maintained.

How to: Display a Dialog Box to Open Excel Files

NoteNote

Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

The following code prompts users to open a new workbook in Microsoft Office Excel 2003 and then 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 file(s):

Example

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

Show: