' A script to demonstrate the File Open dialog available in COMDLG32.OCX ' Written by Rob van der Woude ' http://www.robvanderwoude.com Option Explicit Dim strSelected strSelected = FileOpenDialog( "", "VBScript files|*.vbs" ) If strSelected = "" Then If Err Then WScript.Echo "Error: " & Err.Description Else WScript.Echo "No file selected" End If Else WScript.Echo "Selected file: """ & strSelected & """" End If Function FileOpenDialog( myStartDir, myFileType ) Dim objDialog, strFile, wshShell Const OFN_HIDEREADONLY = &H4 Const OFN_CREATEPROMPT = &H2000 Const OFN_EXPLORER = &H80000 Const OFN_LONGNAMES = &H200000 strFile = "" On Error Resume Next Set objDialog = CreateObject( "MSComDlg.CommonDialog" ) If Err Then MsgBox Err.Description & vbCrLf & vbCrLf & "This script requires COMDLG32.OCX." & vbCrLf & vbCrLf & "Please make sure it is installed and registered.", , "COMDLG32 not registered" Else If myStartDir = "" Then Set wshShell = WScript.CreateObject( "Wscript.Shell" ) objDialog.InitDir = wshShell.CurrentDirectory Set wshShell = Nothing Else objDialog.InitDir = myStartDir End If If myFileType = "" And InStr( myFileType, "|*." ) > 5 Then objDialog.Filter = myFileType objDialog.DefaultExt = Mid( myFileType, InStrRev( myFileType, "." ) + 1 ) Else objDialog.Filter = "All files|*.*" End If strFile = String( 260, Chr(0) ) objDialog.MaxFileSize = 260 objDialog.Flags = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_CREATEPROMPT Or OFN_HIDEREADONLY objDialog.ShowOpen strFile = objDialog.FileName End If On Error Goto 0 Set objDialog = Nothing FileOpenDialog = strFile End Function