Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for comdlgfs.vbs

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

  1. ' A script to demonstrate the File Save dialog available in COMDLG32.OCX
  2. ' Written by Rob van der Woude
  3. ' http://www.robvanderwoude.com
  4.  
  5. Option Explicit
  6.  
  7. Dim strFile
  8.  
  9. strFile = FileSaveDialog( )
  10. If strFile = "" Then
  11. 	If Err Then
  12. 		WScript.Echo "File Save failed: " & Err.Description
  13. 	Else
  14. 		WScript.Echo "File Save was cancelled"
  15. 	End If
  16. Else
  17. 	WScript.Echo "File saved as: """ & strFile & """"
  18. End If
  19.  
  20.  
  21. Function FileSaveDialog( )
  22. ' This function displays a "Save File" dialog and returns the
  23. ' fully qualified path of the entered file name or selected file
  24. 	Dim objDialog, wshShell
  25.  
  26. 	Const OFN_HIDEREADONLY = &H4
  27. 	Const OFN_CREATEPROMPT = &H2000
  28. 	Const OFN_EXPLORER = &H80000
  29. 	Const OFN_LONGNAMES = &H200000
  30.  
  31. 	FileSaveDialog = ""
  32.  
  33. 	Set wshShell = WScript.CreateObject( "Wscript.Shell" )
  34.  
  35. 	On Error Resume Next
  36. 	Set objDialog = CreateObject( "MSComDlg.CommonDialog" )
  37. 	If Err Then
  38. 		MsgBox "This script requires COMDLG32.OCX." & vbCrLf & vbCrLf & "Please make sure it is installed and registered.", , "COMDLG32 not registered"
  39. 	Else
  40. 		objDialog.MaxFileSize = 260
  41. 		objDialog.Flags = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_CREATEPROMPT Or OFN_HIDEREADONLY
  42. 		objDialog.InitDir = wshShell.CurrentDirectory
  43. 		objDialog.DefaultExt = "vbs"
  44. 		objDialog.Filter = "VBScript files|*.vbs"
  45. 		objDialog.ShowSave
  46. 		FileSaveDialog = objDialog.FileName
  47. 	End If
  48.  
  49. 	Set wshShell  = Nothing
  50. 	Set objDialog = Nothing
  51. End Function
  52.  

page last modified: 2024-02-26; loaded in 0.0181 seconds