Prompting for a Directory

If you need to get a filename, the simplest solution is to use the GetOpenFileName method, as I describe earlier. But if you need to get a directory name only (no file), you have two choices.

■ A Windows API function. This method is a bit more complicated but displays a commonly used (and familiar) dialog box. A limitation is that you can't specify a default or starting directory.

■ Excel's FileDialog object. This method is much easier to implement, and the dialog box resembles the standard Open dialog box. The FileDialog object was introduced in Excel 2002, so it won't work with earlier versions of Excel.

Both of these techniques are described in the sections that follow.

CD- The companion CD-ROM contains a workbook that demonstrates both of these methods. ROM The file is named ® get directory, xlsm.

0 0

Post a comment