0

I am trying to create a simple file select dialog in VBScript. I have searched around for and answer but not come up with a simple solution. I don't need Filter options or the like.

In extended script I would use myFile = File.openDialog().

Can someone give me the VBScript equivalent for Windows 7?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Trevor
  • 525
  • 2
  • 6
  • 19
  • Try `Set oDialog = CreateObject("UserAccounts.CommonDialog")`. Preset `oDialog.Filter` and `oDialog.InitialDir` properties and invoke `intResult = oDialog.ShowOpen`. Then, if `intResult` is non-zero, check `oDialog.FileName` property – JosefZ Nov 24 '14 at 01:09
  • CreateObject("UserAccounts.CommonDialog") only works xp? So it looks like. – Trevor Nov 24 '14 at 01:17

1 Answers1

3

I found the below snippet using shell script over here https://gist.github.com/mlhaufe/1034241

Function BrowseForFile()
Dim shell : Set shell = CreateObject("Shell.Application")
Dim file : Set file = shell.BrowseForFolder(0, "Choose a file:", &H4000)
BrowseForFile = file.self.Path
End Function 
MsgBox BrowseForFile 

It seems to work well. Interested if there's a simple "pure vbs" version.

Trevor
  • 525
  • 2
  • 6
  • 19