Skip to content

Instantly share code, notes, and snippets.

Created January 13, 2020 01:11
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Option Explicit
WScript.Echo ChooseFile( )
Function ChooseFile( )
' Select File dialog based on a script by Mayayana
' Known issues:
' * Tree view always opens Desktop folder
' * In Win7/IE8 only the file NAME is returned correctly, the path returned will always be C:\fakepath\
' * If a shortcut to a file is selected, the name of that FILE will be returned, not the shortcut's
On Error Resume Next
Dim objIE, strSelected
ChooseFile = ""
Set objIE = CreateObject( "InternetExplorer.Application" )
objIE.visible = False
objIE.Navigate( "about:blank" )
Do Until objIE.ReadyState = 4
objIE.Document.Write "<HTML><BODY><INPUT ID=""FileSelect"" NAME=""FileSelect"" TYPE=""file""><BODY></HTML>"
With objIE.Document.all.FileSelect
strSelected = .value
End With
Set objIE = Nothing
ChooseFile = strSelected
End Function
Option Explicit
Dim strPath
strPath = SelectFolder( "Select a folder:" )
If strPath = vbNull Then
WScript.Echo ""
WScript.Echo strPath
End If
Function SelectFolder( title )
' This function opens a "Select Folder" dialog and will
' return the fully qualified path of the selected folder
' Argument:
' myStartFolder [string] the root folder where you can start browsing;
' if an empty string is used, browsing starts
' on the local computer
' Returns:
' A string containing the fully qualified path of the selected folder
' Written by Rob van der Woude
' Standard housekeeping
Dim objFolder, objItem, objShell
' Custom error handling
On Error Resume Next
SelectFolder = vbNull
' Create a dialog object
Set objShell = CreateObject( "Shell.Application" )
Set objFolder = objShell.BrowseForFolder( 0, title, 0, "" )
' Return the path of the selected folder
If IsObject( objfolder ) Then SelectFolder = objFolder.Self.Path
' Standard housekeeping
Set objFolder = Nothing
Set objshell = Nothing
On Error Goto 0
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment