Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Prompt user with "open file" dialog box...

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1303
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Prompt user with "open file" dialog box...
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Prompt user with "open file" dialog box... - 8/30/2004 3:56:28 AM   
  GFritz34

 

Posts: 7
Score: 0
Joined: 8/30/2004
From:
Status: offline
I'm writing a VB script for an application.

From my stand alone application I can pass values to an existing excel sheet, and I can retrieve values from an existing excel excel.

My next step is to create a situation where the user is offered a open file pop up window that contains all the files in a folder.

ie: I have a folder named "Recipe", when the user hits my "load" button the window pops up the recipe folder and displays all the excel sheets contained in that folder. The user then selects the appropriate file and hits open. This then executes my script which passes the values from my excel spread sheet to my application.

I also need this same type of feature in reverse... where the user can press my "Save" button, which prompts them to name the file, and saves it into my "Recipe" folder as an excel sheet.

I was under the understandign that the open file and save as pop-up windows had a unique text within VB similar to the .MsgBox argument.

Any help with this would be greatly appreciated
 
 
Post #: 1
 
 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

(in reply to GFritz34)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Prompt user with "open file" dialog box... Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts