Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for selfile.vbs

(view source code of selfile.vbs as plain text)

  1. Option Explicit
  2.  
  3. WScript.Echo "Selected file: " & ChooseFile( )
  4.  
  5.  
  6. Function ChooseFile( )
  7. ' Select File dialog based on a script by Mayayana
  8. ' Known issues:
  9. ' * Tree view always opens Desktop folder
  10. ' * In Win7/IE8 only the file NAME is returned correctly, the path returned will always be C:\fakepath\
  11. ' * If a shortcut to a file is selected, the name of that FILE will be returned, not the shortcut's
  12. 	On Error Resume Next
  13. 	Dim objIE, strSelected
  14. 	ChooseFile = ""
  15. 	Set objIE = CreateObject( "InternetExplorer.Application" )
  16. 	objIE.visible = False
  17. 	objIE.Navigate( "about:blank" )
  18. 	Do Until objIE.ReadyState = 4
  19. 	Loop
  20. 	objIE.Document.Write "<HTML><BODY><INPUT ID=""FileSelect"" NAME=""FileSelect"" TYPE=""file""><BODY></HTML>"
  21. 	With objIE.Document.all.FileSelect
  22. 		.focus
  23. 		.click
  24. 		strSelected = .value
  25. 	End With
  26. 	objIE.Quit
  27. 	Set objIE = Nothing
  28. 	ChooseFile = strSelected
  29. End Function
  30.  

page last uploaded: 2017-07-06, 12:37