Link to home
Start Free TrialLog in
Avatar of Christopher Schene
Christopher ScheneFlag for United States of America

asked on

How do I browse to and choose a directory in VBscript using a File dialog?

I have the following code attached that will browse and choose a file in VBscript.

Instead of choosing a file, I want to choose a directory: How do  I do that?

Function  doFileOpenDialog() 
  Dim oCDlg 
  Dim sTmp 
 
  Set oCDlg = CreateObject( "MSComDlg.CommonDialog" ) 
  If oCDlg Is Nothing Then 
     MsgBox "CreateObject( 'MSComDlg.CommonDialog' ) failed." 
     Exit Sub 
  End If 
 
  oCDlg.MaxFileSize = 10000 
  oCDlg.DialogTitle = "Choose directory"
' Setting other oCDlg.Properties 
' oCDlg.Filter      = ... 
' ... 
 
  oCDlg.ShowOpen 
 
  doFileOpenDialog = oCDlg.Filename  ' FSpec 
 
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DrunkenELF
DrunkenELF
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Christopher Schene

ASKER

thanks for the fast response....it works well!