Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Windows File Open/Save Dialog

Reply
 
Old 09-25-2008   #1 (permalink)
Jeff C


 
 

Windows File Open/Save Dialog

Good Morning All:
I have a number of simple file copy and move .vbs scripts I have scheduled
with the task scheduler however the file object names occassionally change
due to user error etc. An example of script:

strFileDate = Mid(Date -1,1,2) &Mid(Date -1,4,2) &Mid(Date -1,9,2)
Yday = DateAdd("d",-1,Date)
strDay = DatePart("d",Yday,2)
strMonth = DatePart("m",Yday,2)
strYear = Right(DatePart("yyyy",Date), 2)
Set objF1 = CreateObject("Scripting.FileSystemObject")
objF1.copyfile "R:\folder\DOC.pdf", "S:\folder2\DOC.pdf"
objF1.GetFile("S:\Folder2\DOC.pdf").Name = "Midnight On" & " " & strMonth &
" " & strDay & " " & strYear&".pdf"
objF1.movefile "R:\Folder\DOC.pdf" , "V:\Midnight On" & " " & strMonth & " "
& strDay & " " & strYear&".pdf"

The file "Doc.pdf" is a default name given by a scanner but the actual file
could be named Doc001.pdf or Doc002.pdf.

Is there a way to insert a call for the Windows File Open/Save As Dialog so
that a user could invoke the process manually rather than leaving the process
in the task scheduler?

Thanks in advance.


--
Jeff C
Live Well .. Be Happy In All You Do

My System SpecsSystem Spec
Old 09-25-2008   #2 (permalink)
mr_unreliable


 
 

Re: Windows File Open/Save Dialog

Jeff C wrote:
Quote:

> Is there a way to insert a call for the Windows File Open/Save As Dialog so
> that a user could invoke the process manually rather than leaving the process
> in the task scheduler?
>
hi Jeff,

There are at least three ways to do this.

Way 1: The usual recommendation you get here is to use a hidden
copy of IE, and implementing an input tag with type = file. This
will get you an open dialog and with some scripting you can allow
the user to select a file. There is also some mention of using
the OLECMD SaveAs. You can use Google Advanced Group search to
find sample code. Start here:

http://groups.google.com/group/micro...97b029d452bc86

Way 2: There are various actX objects around, capable of showing
the open and saveas dialogs. If you don't mind using a 3rd-party
control, then this is probably the easiest way. Otherwise, you
could write the control yourself. I wrote one such control, and
it only took a few lines of (vb) code.

Way 3: (for hard-core propeller-head geeks only). You could use
the system api directly from script, to get the open and saveas
dialogs. If you are interested in this approach, look up
DynaWrap and/or DynaCall for calling api's directly from script.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
My System SpecsSystem Spec
Old 09-25-2008   #3 (permalink)
mr_unreliable


 
 

uh-oh, forgot one

mr_unreliable wrote:
Quote:

> hi Jeff,
>
> There are at least three ways to do this.
>
uh-oh, there is at least another way, i.e., you can use
microsoft's "comdlg32.ocx" (common dialog control), --
if you have it. However, that was part of vb5/6, and
microsoft is now promoting vb.net. But you may still
have it around, if you happen to be have a copy of the
vb5/6 compiler on your system, or if you are running any
apps which were programmed in vb/6.

If you do have it, here is some code, showing how to
use it:

--- <code> ---
' demo msComDlg.ocx (i.e., comdlg32.ocx) SaveAs Dialog, jw 22May01
Option Explicit
'
Dim oCD : Set oCD = CreateObject("MSComDlg.CommonDialog")
Dim sFile : sFile = String(260, Chr(0))
'
' some comm dlg constants...
Const OFN_HIDEREADONLY = &H4
Const OFN_CREATEPROMPT = &H2000
Const OFN_EXPLORER = &H80000
Const OFN_LONGNAMES = &H200000

With oCD
' setup parameters...
.Flags = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_CREATEPROMPT Or
OFN_HIDEREADONLY
.MaxFileSize = 260 ' allocate space for file name
.InitDir = "c:\windows\" ' set opening directory
.DefaultExt = "txt" ' default extension
.Filter = "Text Files (*.txt) | *.txt | All Files (*.*) | *.* " '
show file types
.FilterIndex = 2 ' show all files
.FileName = "defaultfile.txt" ' set default filename

.ShowSave ' show the dialog

sFile = .FileName ' retrieve the result...
End With

MsgBox("you selected: " & vbCrLf & vbCrLf & " " & sFile) ' report
result

Set oCD = nothing ' clean up
WScript.Quit
--- </code> ---

That code will only get you the saveas dialog, but "comdlg32.ocx"
also has a "ShowOpen" method with similar parameters.

cheers, jw
My System SpecsSystem Spec
Old 09-25-2008   #4 (permalink)
Jeff C


 
 

RE: uh-oh, forgot one


--
Jeff C
Live Well .. Be Happy In All You Do


"mr_unreliable" wrote:
Quote:

> mr_unreliable wrote:
Quote:

> > hi Jeff,
> >
> > There are at least three ways to do this.
> >
>
> uh-oh, there is at least another way, i.e., you can use
> microsoft's "comdlg32.ocx" (common dialog control), --
> if you have it. However, that was part of vb5/6, and
> microsoft is now promoting vb.net. But you may still
> have it around, if you happen to be have a copy of the
> vb5/6 compiler on your system, or if you are running any
> apps which were programmed in vb/6.
>
> If you do have it, here is some code, showing how to
> use it:
>
> --- <code> ---
> ' demo msComDlg.ocx (i.e., comdlg32.ocx) SaveAs Dialog, jw 22May01
> Option Explicit
> '
> Dim oCD : Set oCD = CreateObject("MSComDlg.CommonDialog")
> Dim sFile : sFile = String(260, Chr(0))
> '
> ' some comm dlg constants...
> Const OFN_HIDEREADONLY = &H4
> Const OFN_CREATEPROMPT = &H2000
> Const OFN_EXPLORER = &H80000
> Const OFN_LONGNAMES = &H200000
>
> With oCD
> ' setup parameters...
> .Flags = OFN_EXPLORER Or OFN_LONGNAMES Or OFN_CREATEPROMPT Or
> OFN_HIDEREADONLY
> .MaxFileSize = 260 ' allocate space for file name
> .InitDir = "c:\windows\" ' set opening directory
> .DefaultExt = "txt" ' default extension
> .Filter = "Text Files (*.txt) | *.txt | All Files (*.*) | *.* " '
> show file types
> .FilterIndex = 2 ' show all files
> .FileName = "defaultfile.txt" ' set default filename
>
> .ShowSave ' show the dialog
>
> sFile = .FileName ' retrieve the result...
> End With
>
> MsgBox("you selected: " & vbCrLf & vbCrLf & " " & sFile) ' report
> result
>
> Set oCD = nothing ' clean up
> WScript.Quit
> --- </code> ---
>
> That code will only get you the saveas dialog, but "comdlg32.ocx"
> also has a "ShowOpen" method with similar parameters.
>
> cheers, jw
This is great info, I'll give it a shot in a bit and post back the results
- Thank you very much
My System SpecsSystem Spec
Old 09-25-2008   #5 (permalink)
Reventlov


 
 

Re: Windows File Open/Save Dialog

Il giorno Thu, 25 Sep 2008 05:33:01 -0700, =?Utf-8?B?SmVmZiBD?=
<JeffC@xxxxxx> ha scritto:
Quote:

>Good Morning All:
>I have a number of simple file copy and move .vbs scripts I have scheduled
>with the task scheduler however the file object names occassionally change
>due to user error etc. An example of script:
way 1 provided years ago from Mayayana

msgbox ChooseFile()

Function ChooseFile()
On Error Resume Next
Dim Q2, sRet
Q2 = chr(34)
ChooseFile = ""
Set IE = CreateObject("InternetExplorer.Application")
IE.visible = False
IE.Navigate("about:blank")
Do Until IE.ReadyState = 4
Loop
IE.Document.Write "<HTML><BODY><INPUT ID=" & Q2 & "Fil" & Q2 & "Type=" & Q2 & "file" & Q2
& "><BODY></HTML>"
With IE.Document.all.Fil
.focus
.click
sRet = .value
End With
IE.Quit
Set IE = Nothing
ChooseFile = sRet
End Function
--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--
My System SpecsSystem Spec
Old 09-25-2008   #6 (permalink)
Reventlov


 
 

Re: uh-oh, forgot one

Il giorno Thu, 25 Sep 2008 13:13:37 -0400, mr_unreliable
<kindlyReplyToNewsgroup@xxxxxx> ha scritto:
Quote:

>mr_unreliable wrote:
Quote:

> > hi Jeff,
>>
>> There are at least three ways to do this.
>>
>
>uh-oh, there is at least another way, i.e., you can use
>microsoft's "comdlg32.ocx" (common dialog control),
I miss the licence for the common dialog boxes..

Another way (fifth?): userAccounts.


Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"

objDialog.FilterIndex = 1
objDialog.InitialDir = "C:\Scripts"
intResult = objDialog.ShowOpen

If intResult = 0 Then
Wscript.Quit
Else
Wscript.Echo objDialog.FileName
End If

--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--
My System SpecsSystem Spec
Old 09-26-2008   #7 (permalink)
mr_unreliable


 
 

Re: uh-oh, forgot one

Reventlov wrote:
Quote:

> I miss the licence for the common dialog boxes..
>
Yes, comdlg32.ocx is a licensed control. If you have
any version of vb5/6 installed, then you will have the
proper license installed also.

The license is a registry entry. If you search around,
you can probably find the license code (i.e., registry
entries) for microsoft's (old vb) licensed controls.

Years ago, installing a license without purchasing the
appropriate product would have resulted in an immediate
call from the microsoft legal staff, with threats for
prosecution and jail time. Now-a-days, with vb5/6 having
been abandoned by microsoft, and probably forgotten,
making use of something that microsoft no longer cares
about would probably get you a much "lighter sentence"
-- a reprimand, a fine, and about 100 hours of community
service time.

cheers, jw
My System SpecsSystem Spec
Old 09-26-2008   #8 (permalink)
Reventlov


 
 

Re: uh-oh, forgot one

Il giorno Fri, 26 Sep 2008 12:26:16 -0400, mr_unreliable
<kindlyReplyToNewsgroup@xxxxxx> ha scritto:
Quote:

>Reventlov wrote:
Quote:

>> I miss the licence for the common dialog boxes..
Quote:

>making use of something that microsoft no longer cares
>about would probably get you a much "lighter sentence"
>-- a reprimand, a fine, and about 100 hours of community
>service time.
In my second youth I'm trying to use only legal software even at home, where years ago I
would have installed everything pirated. I must say today it's easier to find high
performance free software.
If i steal a license number for the common dialog boxes I'll try to be assigned to 100
hours of work in this newsgroup, maybe before you end yours. :-)

--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--
My System SpecsSystem Spec
Old 09-27-2008   #9 (permalink)
Jeff C


 
 

Re: uh-oh, forgot one

> >mr_unreliable wrote:
Quote:
Quote:
Quote:

> > > hi Jeff,
> >>
> >> There are at least three ways to do this.
> >>
> >
> >uh-oh, there is at least another way, i.e., you can use
> >microsoft's "comdlg32.ocx" (common dialog control),
>
> I miss the licence for the common dialog boxes..
>
> Another way (fifth?): userAccounts.
>
>
> Set objDialog = CreateObject("UserAccounts.CommonDialog")
> objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
>
> objDialog.FilterIndex = 1
> objDialog.InitialDir = "C:\Scripts"
> intResult = objDialog.ShowOpen
>
> If intResult = 0 Then
> Wscript.Quit
> Else
> Wscript.Echo objDialog.FileName
> End If
Thanks to Both Unreliable and Reventlov: !!

The following is what I got to work - no License for me so I couldn't get
that to work but I'll continue to play around with this:

Dim dialog
Set wshshell = CreateObject("wscript.shell")
Set Dialog = CreateObject("UserAccounts.CommonDialog")

Dialog.Filter = "PDF Files|*.PDF"
Dialog.InitialDir = "R:\"
intResult = Dialog.ShowOpen
If intResult = 0 Then
Wscript.Quit
Else
wshshell.run Chr(34) & dialog.FileName & Chr(34)
End If

Cheers and a fine weekend to you both
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
File Open/Save Dialog not responding Vista General
Windows Open / Save Dialog Shortcuts Vista General
File Open/Save Dialog Box hangs all applications Vista General
Save As and Open dialog in Office Vista file management
File Open and File Save As Dialog Freeze and Hang All Applications Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46