how to call the Open File Dialog from .VBS, let the user select a file and
return the full file name to .VBS ?
Regards Marcus
> how to call the Open File Dialog from .VBS, let the user select a file
> and return the full file name to .VBS ?
There is no nice GUI for fileselection built into VBscript. If you have
Microsoft Excel installed you can however use that behind the back of your
user to get the dialog you need. The following code sniplet will write the
name of the file you select to the console if Excel is installed:
____________________________
Option Explicit
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
WScript.Echo oExcel.GetOpenFilename()
____________________________
GetOpenFilename is documented here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/wmisdk/wmi/getting_management_information_from_an_existing_application.a
sp
--
Claus Andersen, cl...@wheel.dk
"Rosebud"
> how to call the Open File Dialog from .VBS, let the user select a file and
> return the full file name to .VBS ?
Hi
Go here
http://home.att.net/~wshvbs/index.htm
and search for
Using the system "Open" and "SaveAs" Common Dialogs...
--
torgeir
VBScript itself doesn't provide any UI for use. However, we can invoke
other component to implement the same task.
In this case, we can create an instance of the MSComDlg.CommonDialog
(comdlg32.ocx). Below is the code snippet:
Option Explicit
' Windows Common Dialogue Error Constant:
' The selected file must exist, non-existent file entry
' will prompt for existing file
Const cdlOFNFileMustExist = &H1000
Dim oDlg1, sFileName
' selecting the Cancel button generates an error so disable
' error notification
On Error Resume Next
' create a common dialog object
Set oDlg1 = wscript.CreateObject("MSComDlg.CommonDialog")
' set the dialog's properties
With oDlg1
.DialogTitle = "Select the script you want to open..."
.Filter = "JScript Files (*.js)|*.js|VBScript Files(*.vbs)|*.vbs"
.FilterIndex = 2
.MaxFileSize = 260
.Flags = cdlOFNFileMustExist
' display the Open File Dialog
.ShowOpen
'assign the filename selected to a variable for validation**
sFileName = .FileName
End With
If sFileName <> "" Then
WScript.Echo sFileName
End If
' exit the script
WScript.Quit
To make the code above run, you should make sure that the comdlg32.ocx
exists on the machine. The comdlg32.ocx was shipped with many products.
Please check it at
http://support.microsoft.com/default.aspx?scid=/servicedesks/fileversion/dll
info.asp&fp=1.
Gary
This posting is provided "AS IS", with no warranties, and confers no
rights. Enjoyed ASP.NET? http://www.asp.net
1) If you call:
Set shellapp = createobject("Shell.Application")
Set FolOrFil = shellapp.BrowseForFolder(0, "Select file.", 16384)
you'll show the BrowseForFolder dialogue with files showing,
but it's a pain to extract the path. FolOrFil will return only the file
(or folder) name selected.
2) You can also tap into the IE file browsing ability to show an
IE window with a browse button that will return the path selected.
3) Use a component.
For samples of 1 and 2:
http://www.jsware.net/jsware/scripts.html (ShellApp scripts)
For #3 scroll down to the components section.
--
--
Marcus Moehrmann <mar...@typolog.de> wrote in message
news:3d5f6...@news.arcor-ip.de...
Windows Script Host 2 Developers Guide - MSPress 2000
- Mitch Gallant
http://home.istar.ca/~neutron/wsh