30.04.2017 Views

4523756273

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

248<br />

Part IV: Communicating with Your Users<br />

Figure 15-8 shows the result of running this procedure. The message box displays<br />

the filenames that were selected.<br />

Figure 15-8:<br />

Select<br />

multiple<br />

filenames<br />

by using the<br />

GetOpen-<br />

Filename<br />

method.<br />

Notice that I use a named argument for the GetOpenFilename method. I also<br />

set the MultiSelect argument to True. The other arguments are omitted, so<br />

they take on their default values. Using named arguments eliminates the need<br />

to specify arguments that aren’t used.<br />

The FileNames variable is defined as a Variant data type. I use the IsArray<br />

function to determine whether FileName contains an array. If so, the code<br />

uses the VBA LBound and UBound functions to determine the array’s lower<br />

and upper bounds and build a message that consists of each array element. If<br />

FileNames is not an array, that means the user clicked the Cancel button (the<br />

FileNames variable contains an array even if only one file is selected).<br />

The GetSaveAsFilename Method<br />

The Excel GetSaveAsFilename method works just like the GetOpenFilename<br />

method, but it displays the Excel Save As dialog box rather than its Open<br />

dialog box. The GetSaveAsFilename method gets a path and filename from<br />

the user but doesn’t do anything with it. It’s up to you to write code that<br />

actually saves the file.<br />

The syntax for this method follows:<br />

object.GetSaveAsFilename ([InitialFilename], [FileFilter],<br />

[FilterIndex], [Title], [ButtonText])<br />

The GetSaveAsFilename method takes Table 15-6’s arguments, all of which<br />

are optional.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!