I have the following script that is used to open the file browser window so that I could select a file and then write the selected file name out to a text file. It worked fine in Window 7 and 8.1 but not in Windows 10.
Dim objShell
Dim strFileName
Dim strFilePath
Dim objFile
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
Set objFile = objShell.BrowseForFolder(0, "Choose a file:", &H4000,17)
strFileName = objFile.Title
strFilePath = objFile.self.Path
Set ts = objFSO.CreateTextFile("C:\Temp\Folder.txt",True)
ts.Write strFilePath
ts.Close
It opens the window to select the folder and file but when I click OK I get the following error:
script: c:\Users\xxxxx\desktop\filelist.vbs
Line: 8
Char: 1
Error: Unspecified error
Code: 80004005
Source: (null)
If I set the &H4000 to &H0001 which means to only show folders I can select a folder and it works fine.
From other research I've seen it looks like this has to do with the version of the shell32.dll.
Anyone know of another way to allow a user to select a file and getting back the selected file's path and name?
Thank you!