Skip to content

Instantly share code, notes, and snippets.

@AlexLaforge
Forked from simply-coded/BrowseForFile.md
Created June 6, 2019 18:03
Show Gist options
  • Save AlexLaforge/c06133e9dd8270f59e9af39ce4d26816 to your computer and use it in GitHub Desktop.
Save AlexLaforge/c06133e9dd8270f59e9af39ce4d26816 to your computer and use it in GitHub Desktop.
Browse for file dialog box in VBScript.
Function BrowseForFile()
'@description: Browse for file dialog.
'@author: Jeremy England (SimplyCoded)
BrowseForFile = CreateObject("WScript.Shell").Exec( _
"mshta.exe ""about:<input type=file id=f>" & _
"<script>resizeTo(0,0);f.click();new ActiveXObject('Scripting.FileSystemObject')" & _
".GetStandardStream(1).WriteLine(f.value);close();</script>""" _
).StdOut.ReadLine()
End Function
filePath = BrowseForFile()
If filePath = "" Then
MsgBox "Operation canceled", vbcritical
Else
MsgBox filePath, vbinformation
End If
'--------------------------------------------------------------------------------------
Function BrowseForFile()
'@description: Browse for file dialog.
'@author: Jeremy England (SimplyCoded)
BrowseForFile = CreateObject("WScript.Shell").Exec( _
"mshta.exe ""about:<input type=file id=f>" & _
"<script>resizeTo(0,0);f.click();new ActiveXObject('Scripting.FileSystemObject')" & _
".GetStandardStream(1).WriteLine(f.value);close();</script>""" _
).StdOut.ReadLine()
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment