VBScript: how to open FileDialog always on top (Vista)
Hey guys,
I am using the following VBscript (found on this forum) to get a filename from the user :
Code:
Function GetFileName()
Set oWord = CreateObject("Word.Application")
msoFileDialogFilePicker = 1
oWord.ChangeFileOpenDirectory("C:\temp\")
oWord.FileDialog(msoFileDialogFilePicker).Title = "Please Select the Additions File"
oWord.FileDialog(msoFileDialogFilePicker).AllowMultiSelect = False
oWord.FileDialog(msoFileDialogFilePicker).Show
oWord.WindowState = 2
For Each objFile in oWord.FileDialog(1).SelectedItems
GetFileName = objFile
Next
oWord.Quit
Set oWord = Nothing
End Function
The problem is that the file browser dialog opens up in the background. I would like to move it to the top. I am running this script on Vista so there is no easy way of using commondialog.
Thanks,
Kavi
Re: VBScript: how to open FileDialog always on top (Vista)
If UCase(.GetExtensionName(oFile.Name)) = Ucase(sExt) Then Exit For
You can find this sort of thing in this downloadable help
file: script56.chm
Re: VBScript: how to open FileDialog always on top (Vista)
Hey EINSTEIN_007,
Thanks for the prompt reply. I don't think this solves the problem. The statement below:
oWord.FileDialog(msoFileDialogFilePicker).Show
opens up the usual file browser dialog. The problem is that the dialog box is behind the application that runs the script. I believe there should be some property that I need to set to true so that the dialog comes on top.
To try your suggestion, I put an unconditional Exit For after the GetFileName = objFile line and that didn't help.
Hope you can help.
Thanks
Re: VBScript: how to open FileDialog always on top (Vista)
Hi kaviyesh,
Did you ever find a solution to this? I have the same issue....
Thanks,
B
Re: VBScript: how to open FileDialog always on top (Vista)
I have developed a workaround if anyone is interested, but would still be open to a better method.
I have written a secondary script that gets called just prior to showing the dialog:
Relevant part of the main script:
Code:
'used to activate the dialog window, when it appears in the background on Win 7
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "C:\BringFileDialogToFront.vbs"
Set objShell = Nothing
Set oWord = CreateObject("Word.Application")
Set MyFilePicker = oWord.FileDialog(3)
With MyFilePicker
.AllowMultiSelect = False
.InitialFileName = "C:\"
.Title = "Please Select the Required File"
.ButtonName = "Select"
End With
If MyFilePicker.Show = -1 Then
MyFile = MyFilePicker.SelectedItems(1)
End If
Separate script to bring the dialog to the front:
Code:
dim WshShell
dim bActivated
dim x
x = 1
set WshShell = WScript.CreateObject("WScript.Shell")
do until bActivated = True
bActivated = WshShell.AppActivate("Please Select the Required File")
WScript.Sleep 100 'wait 0.1 sec
x = x + 1
if x = 10 then bActivated = True
loop
For this to work it needs to be in a separate file. I would love to hear if someone can get this to work as part of a single script.
B