Using the Standard "Open File" dialog box


Posted by Geoff on June 19, 2001 12:30 PM

The following is an example of how do use the "Open File" dialog box according to the VBA help files:

fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
MsgBox "Open " & fileToOpen
End If

My code looks exactly like this (aside from the MsgBox) but when a user chooses a file to Open, I get a "Type Mismatch" error for the If condition since fileToOpen contains a path now, and not a boolean. I have this feeling I'm missing something obvious but I'm not sure what it is.

Thanks,

Geoff

Posted by Geoff on June 19, 2001 12:34 PM

Nevermind, I changed the fileToOpen type to Variant and it works now. Duh.



Posted by Barrie Davidson on June 19, 2001 12:37 PM

Geoff, I tried your code and it works fine for me. Where, in your code, does Excel's debugger put you when you encounter the error?

Barrie