Sample Code to use File Open dialog box 
Author Message
 Sample Code to use File Open dialog box

on error resume next
set WSHShell = wscript.CreateObject("wscript.Shell")
  set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
  comDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
  objDlg.FilterIndex = 2
  objDlg.MaxFileSize = 260
  objDlg.CancelError = true
  objDlg.ShowOpen
strFName = objDlg.Filename
WSHShell.popup strFName

Regards,
Ian Morrish
http://www.*-*-*.com/ WSH FAQ
http://www.*-*-*.com/ (NetMeeting)
http://www.*-*-*.com/



Fri, 02 Feb 2001 03:00:00 GMT  
 Sample Code to use File Open dialog box
Thanks for your code examples! See typing error correction below:
(that statement is silently skipped with the effect that the filter
is not set)

 on error resume next
 set WSHShell = wscript.CreateObject("wscript.Shell")
   set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
   objDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
   ^^^
   objDlg.FilterIndex = 2
   objDlg.MaxFileSize = 260
   objDlg.CancelError = true
   objDlg.ShowOpen
 strFName = objDlg.Filename
 WSHShell.popup strFName

Why not translating the code to JScript? It would be nice practice for
VB programmers to write code with the proper case (upper/lower) in variable names,
so the translation process to JS would be much more straight forward.

var WSHShell = WScript.CreateObject("wscript.Shell");
var objDlg = WScript.CreateObject("MSComDlg.CommonDialog");

objDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs|JScript Files (*.js)|*.js";
objDlg.FilterIndex = 3;         // we are most interested in *.js files ;-)
objDlg.MaxFileSize = 260;
objDlg.CancelError = false;     // no error handler in JScript !!!
objDlg.ShowOpen();
var strFName = objDlg.Filename;
WSHShell.popup(strFName);

Greetings
Herbert

Quote:

> on error resume next
> set WSHShell = wscript.CreateObject("wscript.Shell")
>   set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
>   comDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
>   objDlg.FilterIndex = 2
>   objDlg.MaxFileSize = 260
>   objDlg.CancelError = true
>   objDlg.ShowOpen
> strFName = objDlg.Filename
> WSHShell.popup strFName

> Regards,
> Ian Morrish
> http://wsh.glazier.co.nz WSH FAQ
> http://ils.glazier.co.nz (NetMeeting)
> http://www.glazier.co.nz

--
+----------------------------+------------------------------+
| Herbert Hotz               | Voice:   +41 1 381 2122      |
| APS Applied Systematics AG | Fax:     +41 1 381 2127      |
| Muehle Tiefenbrunnen       | GSM-SMS: +41 79 402 5704     |
| Seefeldstrasse 231         | URL:     http://www.aps.ch/  |

+----------------------------+------------------------------+


Fri, 02 Feb 2001 03:00:00 GMT  
 Sample Code to use File Open dialog box
Spot the error

on error resume next
set WSHShell = wscript.CreateObject("wscript.Shell")
  set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
  objDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs" 'This
line was in error
  objDlg.FilterIndex = 2
  objDlg.MaxFileSize = 260
  objDlg.CancelError = true
  objDlg.ShowOpen
strFName = objDlg.Filename
WSHShell.popup strFName

Sorry!

Quote:

>on error resume next
>set WSHShell = wscript.CreateObject("wscript.Shell")
>  set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
>  comDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
>  objDlg.FilterIndex = 2
>  objDlg.MaxFileSize = 260
>  objDlg.CancelError = true
>  objDlg.ShowOpen
>strFName = objDlg.Filename
>WSHShell.popup strFName

>Regards,
>Ian Morrish
>http://wsh.glazier.co.nz WSH FAQ
>http://ils.glazier.co.nz (NetMeeting)
>http://www.glazier.co.nz



Fri, 02 Feb 2001 03:00:00 GMT  
 Sample Code to use File Open dialog box
Cool, thanks for the code.
Quote:

>on error resume next
>set WSHShell = wscript.CreateObject("wscript.Shell")
>  set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
>  comDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
>  objDlg.FilterIndex = 2
>  objDlg.MaxFileSize = 260
>  objDlg.CancelError = true
>  objDlg.ShowOpen
>strFName = objDlg.Filename
>WSHShell.popup strFName



Fri, 02 Feb 2001 03:00:00 GMT  
 Sample Code to use File Open dialog box
What version of Windows and Browser are you using?

I'm working on a dummy VB app to install all the version 6 controls. Also
installing the VB6 runtime may solve the problem (if there is one)
Regards,
Ian Morrish
http://wsh.glazier.co.nz WSH FAQ
http://ils.glazier.co.nz (NetMeeting)
http://www.glazier.co.nz

Quote:

>Code segment looks interesting, but when I sampled code I get error
>MSComDlg error.

>How do I enable this interface ?

>Evan



>> Cool, thanks for the code.


>> >on error resume next
>> >set WSHShell = wscript.CreateObject("wscript.Shell")
>> >  set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
>> >  comDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
>> >  objDlg.FilterIndex = 2
>> >  objDlg.MaxFileSize = 260
>> >  objDlg.CancelError = true
>> >  objDlg.ShowOpen
>> >strFName = objDlg.Filename
>> >WSHShell.popup strFName



Sat, 03 Feb 2001 03:00:00 GMT  
 Sample Code to use File Open dialog box
OSR2 and IE 4.01

Thanks



Sat, 03 Feb 2001 03:00:00 GMT  
 Sample Code to use File Open dialog box
How do you get this script to open in a certain directory and drive?  And
can you change the
title?

See Ya!

Quote:

>on error resume next
>set WSHShell = wscript.CreateObject("wscript.Shell")
>  set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
>  comDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
>  objDlg.FilterIndex = 2
>  objDlg.MaxFileSize = 260
>  objDlg.CancelError = true
>  objDlg.ShowOpen
>strFName = objDlg.Filename
>WSHShell.popup strFName

>Regards,
>Ian Morrish
>http://wsh.glazier.co.nz WSH FAQ
>http://ils.glazier.co.nz (NetMeeting)
>http://www.glazier.co.nz



Sat, 03 Feb 2001 03:00:00 GMT  
 Sample Code to use File Open dialog box
Here is my problem. I used this script the way Ian Morrish put it. It worked
fine yesterday. I try to run it today, exactly the way it is and now all I
get is a message box that says Windows Scripting Host and an OK button. No
File Dialog box.
What could have happened? I tried it on my other machine as well. Same
thing. I even re copied and past the code as is on the original post to a
new file with the same results.!?!?
Quote:

>on error resume next
>set WSHShell = wscript.CreateObject("wscript.Shell")
>  set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
>  objDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
>  objDlg.FilterIndex = 2
>  objDlg.MaxFileSize = 260
>  objDlg.CancelError = true
>  objDlg.ShowOpen
>strFName = objDlg.Filename
>WSHShell.popup strFName

>Regards,
>Ian Morrish
>http://wsh.glazier.co.nz WSH FAQ
>http://ils.glazier.co.nz (NetMeeting)
>http://www.glazier.co.nz



Sat, 03 Feb 2001 03:00:00 GMT  
 Sample Code to use File Open dialog box
This looks like a capability I could use.  However, I couldn't get it to run
on my machine, even after correcting "comDlg" to "objDlg".

Initially when I execute the code, I get a blank box message box.  By
removing the error handling code, I get "Win32 error 0x80040112".

I am running NT 4.0 with SP1 and IE 4.0 with SP1.  Any ideas?

Quote:

>on error resume next
>set WSHShell = wscript.CreateObject("wscript.Shell")
>  set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
>  comDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs"
>  objDlg.FilterIndex = 2
>  objDlg.MaxFileSize = 260
>  objDlg.CancelError = true
>  objDlg.ShowOpen
>strFName = objDlg.Filename
>WSHShell.popup strFName

>Regards,
>Ian Morrish
>http://wsh.glazier.co.nz WSH FAQ
>http://ils.glazier.co.nz (NetMeeting)
>http://www.glazier.co.nz



Mon, 05 Feb 2001 03:00:00 GMT  
 Sample Code to use File Open dialog box
Thanks for this sample.
Is there a way to select a folder in a similar way ?

Ian Morrish a crit dans le message

Quote:
>...
>on error resume next
>set WSHShell = wscript.CreateObject("wscript.Shell")
>  set objDlg = wscript.CreateObject("MSComDlg.CommonDialog")
>  objDlg.Filter = "All Files (*.*)|*.*|VBScript Files (*.vbs)|*.vbs" 'This
>line was in error
>  objDlg.FilterIndex = 2
>  objDlg.MaxFileSize = 260
>  objDlg.CancelError = true
>  objDlg.ShowOpen
>strFName = objDlg.Filename
>WSHShell.popup strFName
>...



Thu, 22 Feb 2001 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. sample code needed to open plain text file and use as excel97 file

2. Open file dialog box and upload file

3. File Open Dialog box from CmnDlg32.dll?

4. WSH and "Open File" dialog box

5. invoke the Open file dialog box in DHTML

6. Open Multiselect Open dialog box

7. invoke the Open file dialog box in DHTML

8. Open File Dialog Box

9. File Open dialog box

10. opening a browse or file open dialog

11. How to open a GetFilename dialog box

12. Bypass Open/Download Dialog Box

 

 
Powered by phpBB® Forum Software