Here's a complete example showing three different methods to provide a file open dialog to select single or multiple files with a file type filter.
The first two methods use MSHTA and the third uses PowerShell. The PowerShell method provides all the advantages of the other two methods without any disadvantages.
Set oWSH = CreateObject("WScript.Shell")
'BrowseForFileWithFilter1 (MSHTA)
'Pros: Suports basic filtering. Supports multiple file picking.
'Cons: Initial folder cannot be set. Title is fixed at localized "Choose file to upload".
Function BrowseForFileWithFilter1(filter,multi)
separator = "|": m = "": If multi Then m = "multiple"
BrowseForFileWithFilter1 = CreateObject("WScript.Shell").Exec( _
"mshta.exe ""about:<meta http-equiv=X-UA-Compatible content=IE=11>" & _
"<input type=file id=f " & m & " accept='" & filter & "'>" & _
"<script>resizeTo(0,0);f.click();" & _
"files=f.files;fileList='';" & _
"for (i=0;i<files.length;i++){" & _
"fileList+=files[i].name;if(i<files.length-1){fileList+='" & separator & "';}}" & _
"new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(fileList);" & _
"close();</script>""").StdOut.ReadLine()
End Function
'BrowseForFileWithFilter2 (MSHTA)
'Pros: Supports full filtering. Initial folder can be set. Default title is localized "Open" and can be set.
'Cons: Does not support multiple file picking. Initial folder must include * (e.g. C:\*)
Function BrowseForFileWithFilter2(filter,folder,title)
folder = Replace(Replace(Replace(folder,"\\","\"),"\\","\"),"\","\\")
BrowseForFileWithFilter2 = oWSH.Exec("mshta.exe ""about:<object id=d classid=" & _
"clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b></object><script>moveTo(0,999999);" & _
"function window.onload(){new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write" & _
"(d.object.openfiledlg('" & folder & "',null,'" & filter & "','" & title & "'));" & _
"close();}</script><hta:application showintaskbar=no>""").StdOut.ReadAll
End Function
'BrowseForFileWithFilter3 (PowerShell)
'Pros: Supports full filtering. Initial folder can be set. Default title is localized "Open" and can be set. Supports multiple file picking.
'Cons: None
Function BrowseForFileWithFilter3(filter, folder, title, multi)
separator = "|": m = "$false": If multi Then m = "$true"
oWSH.Run "powershell -NoP -Ex bypass -C Add-Type -AssemblyName PresentationFramework; " & _
"$f = New-Object Microsoft.Win32.OpenFileDialog; $f.Multiselect = " & m & "; " & _
"$f.InitialDirectory = '" & folder & "'; $f.Filter = '" & filter & "'; $f.Title = '" & title & "'; " & _
"$f.ShowDialog(); $files = $f.FileNames -join '" & separator & "'; " & _
"$r = 'HKCU:\Software\SelectedFile'; " & _
"if (-not (Test-Path $r)) { New-Item -Path $r }; " & _
"Set-ItemProperty -Path $r -Name '(default)' -Value $files", 0, True
BrowseForFileWithFilter3 = oWSH.RegRead("HKCU\Software\SelectedFile\")
End Function
Response = MsgBox("Click OK to begin",vbOKCancel,"File selection demo")
If Response=2 Then WScript.Quit
'Single selection (MSHTA 1):
SelectedFile = BrowseForFileWithFilter1(".txt",false)
Response = MsgBox(SelectedFile,vbOKCancel,"Selected file:")
If Response=2 Then WScript.Quit
'Multi selection (MSHTA 1):
SelectedFile = BrowseForFileWithFilter1(".txt",true)
Response = MsgBox(SelectedFile,vbOKCancel,"Selected file(s):")
If Response=2 Then WScript.Quit
'Single selection (MSHTA 2):
SelectedFile = BrowseForFileWithFilter2("Text Files (*.txt)|*.txt", "", "")
Response = MsgBox(SelectedFile,vbOKCancel,"Selected file:")
If Response=2 Then WScript.Quit
'Single selection (PowerShell):
SelectedFile = BrowseForFileWithFilter3("Text files (*.txt)|*.txt", "", "", False)
Response = MsgBox(SelectedFile,vbOKCancel,"Selected file:")
If Response=2 Then WScript.Quit
'Multi selection (PowerShell):
SelectedFile = BrowseForFileWithFilter3("Text files (*.txt)|*.txt", "", "", True)
Response = MsgBox(SelectedFile,vbOKCancel,"Selected file(s):")
If Response=2 Then WScript.Quit
Another option, is to use an external file dialog app, such as the one at the following link. This provides all the features of the PowerShell method plus a modern folder selector and more:
https://lesferch.github.io/FileDialog/
id='files' name='files[]'- are you not allowed to select multiple files or do you have issue showing values when you read resultsmultipleattribute was not supported before IE10 or even IE11, in which document mode you run the app?