Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 21-07-2010
Member
 
Join Date: Jul 2010
Posts: 2
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
Reply With Quote
  #2  
Old 21-07-2010
Member
 
Join Date: Dec 2007
Posts: 2,273
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
Reply With Quote
  #3  
Old 21-07-2010
Member
 
Join Date: Jul 2010
Posts: 2
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
Reply With Quote
  #4  
Old 19-10-2010
Member
 
Join Date: Oct 2010
Posts: 2
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
Reply With Quote
  #5  
Old 21-10-2010
Member
 
Join Date: Oct 2010
Posts: 2
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "VBScript: how to open FileDialog always on top (Vista)"
Thread Thread Starter Forum Replies Last Post
Can't open folders on vista zMatt_- Windows Software 1 14-09-2010 08:44 AM
Use of FileDialog class Gadin Software Development 5 25-02-2010 08:39 AM
IE 7 will not open with Vista billj818 Technology & Internet 4 11-05-2009 10:23 AM
Application FileDialog problem Deep23 Software Development 3 30-04-2009 11:50 PM
Can't open images in Vista Iesa Operating Systems 3 20-02-2009 10:38 PM


All times are GMT +5.5. The time now is 08:25 AM.