Login | |
|
 |
Re: Prompt user with "open file" dialog box... - 8/30/2004 5:21:28 AM
|
|
 |
|
| |
mbouchard
Posts: 1903
Score: 14
Joined: 5/15/2003
From: USA
Status: offline
|
Here is a script that I found a while ago while I was looking at the ShellApp features. It might help you get started. For more info look for ShellApp on MSDN or TechNet quote: '---FileBrowser.vbs demonstrates a class block that enables a file browsing window. '--see the info. file for details. '--this script updated 11-7-01: '--As it was previously written, the script would keep running if the '--IE window was closed from the control box ("x" in upper right). '--(Also, the script was creating an instance of Wscript.Shell for no reason. '--That was apparently a leftover from earlier experiments.) '---------------------------------------- Dim ob, s set ob = New FindFile s = ob.Browse msgbox s set ob = nothing '-----------------BEGIN CLASS BLOCK ----------------------------------- '-- Use: Set obj = New FindFile '-- var = obj.Browse '-------------- var is path of file selected. ----------------------------- '--------------------------------------------------------------------- Class FindFile Private fso, sPath1 '--FileSystemObject needed to check file path: Private Sub Class_Initialize() Set fso = CreateObject("Scripting.FileSystemObject") end sub '---------------release FSO when class is released: Private Sub Class_Terminate() Set FSO = Nothing End sub '--The public one function in this class: Public Function Browse() on error resume next sPath1 = GetPath Browse = sPath1 end function Private Function GetPath() Dim Ftemp, ts, IE, sPath '-----------Get the TEMP folder path and create a text file in it: Ftemp = fso.GetSpecialFolder(2) Ftemp = Ftemp & "\FileBrowser.html" set ts = fso.CreateTextFile(Ftemp, true) '----------------------write the webpage needed for file browsing window: ts.WriteLine "<HTML><HEAD><TITLE></TITLE></HEAD>" ts.WriteLine "<BODY BGCOLOR=" & chr(34) & "#F3F3F8" & chr(34) & " TEXT=" & chr(34) & "black" & chr(34) & ">" ts.WriteLine "<script language=" & chr(34) & "VBScript" & chr(34) & ">" '--------when OK is clicked assign path to statustext property: ts.WriteLine "sub but_onclick()" ts.WriteLine "status = document.forms(0).elements(0).value" ts.WriteLine "end sub" '--------when CANCEL is clicked assign "cancel" to statustext property: ts.WriteLine "sub butc_onclick()" ts.WriteLine "status = " & chr(34) & "cancel" & chr(34) ts.WriteLine "end sub" ts.WriteLine "</script>" ts.WriteLine "<DIV ALIGN=" & chr(34) & "center" & chr(34) & ">" ts.WriteLine "<FONT FACE=" & Chr(34) & "arial" & Chr(34) & " SIZE=2>" ts.WriteLine "<BR>" ts.WriteLine "<FORM>" '-----------this is the file browsing box in webpage: ts.WriteLine "<INPUT TYPE=" & chr(34) & "file" & chr(34) & "></input>" '-----------this is the OK button: ts.WriteLine "<input type=" & chr(34) & "button" & chr(34) & " id=" & chr(34) & "but" & chr(34) & " value=" & chr(34) & "OK" & chr(34) & "></input>" ts.WriteLine "<BR><BR>" '------------this is the CANCEL button: ts.WriteLine "<input type=" & chr(34) & "button" & chr(34) & " id=" & chr(34) & "butc" & chr(34) & " value=" & chr(34) & "CANCEL" & chr(34) & "></input>" ts.WriteLine "<BR><BR> Browse for file, then click OK." ts.WriteLine "</FORM>" ts.WriteLine "</FONT></DIV>" ts.WriteLine "</BODY></HTML>" ts.Close set ts = nothing on error resume next '--webpage is written. now have IE open it: Set IE = Wscript.CreateObject("InternetExplorer.Application") IE.Navigate "file:///" & Ftemp IE.AddressBar = false IE.menubar = false IE.ToolBar = false IE.width = 400 IE.height = 250 IE.resizable = false IE.visible = true '--do a loop every 1/2 second until either: '-- the browsing window value is a valid file path or '-- CANCEL is clicked (setting IE.StatusText to "cancel") or '--IE is closed from the control box. do while IE.visible = true spath = IE.StatusText '--------get statustext value. if fso.FileExists(spath) = true or spath = "cancel" or IE.visible = false then exit do end if wscript.sleep 500 loop IE.visible = false IE.Quit set IE = nothing if fso.FileExists(spath) = true then GetPath = spath else GetPath = "" end if End Function End Class
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|