Results 1 to 5 of 5

Thread: VBScript: how to open FileDialog always on top (Vista)

  1. #1
    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

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    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

  3. #3
    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

  4. #4
    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

  5. #5
    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

Similar Threads

  1. Can't open folders on vista
    By zMatt_- in forum Windows Software
    Replies: 1
    Last Post: 14-09-2010, 08:44 AM
  2. Use of FileDialog class
    By Gadin in forum Software Development
    Replies: 5
    Last Post: 25-02-2010, 08:39 AM
  3. IE 7 will not open with Vista
    By billj818 in forum Technology & Internet
    Replies: 4
    Last Post: 11-05-2009, 10:23 AM
  4. Application FileDialog problem
    By Deep23 in forum Software Development
    Replies: 3
    Last Post: 30-04-2009, 11:50 PM
  5. Can't open images in Vista
    By Iesa in forum Operating Systems
    Replies: 3
    Last Post: 20-02-2009, 10:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,841,963.13588 seconds with 17 queries