Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Feb 2003
    Location
    Runcorn, Cheshire, United Kingdom
    Posts
    372
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Open Explorer with Focus (VBA)

    I'm trying to get a VBA script to open a folder in the foreground. (maybe a folder containing photos so that the user can select one to use). I've managed to get it to start up explorer.exe with the right path, but it always opens in the background, i.e. behind the Excel spreadsheet that contains the code. What I want is for someone to click a toobar button and expect the folder to open as the topmost item on the desktop.

    Does anyone know how best to do this ?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Open Explorer with Focus (VBA)

    What code are you using at present?

  3. #3
    3 Star Lounger
    Join Date
    Feb 2003
    Location
    Runcorn, Cheshire, United Kingdom
    Posts
    372
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Open Explorer with Focus (VBA)

    Hi Hans,
    The code I'm using is

    <pre>MyPath = "Cipeximages"
    Debug.Print MyPath
    If MyPath = "" Then
    OK = MsgBox("File Not Saved, no current folder defined", vbOKOnly)
    Else
    callit = "explorer /n, """ & MyPath & """"
    Debug.Print callit
    OK = Shell(callit)
    End If </pre>


    The value of "callit" in the Shell command is <pre>explorer /n, "Cipeximages"</pre>


    The window opens with no problem, but you can't see it.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Open Explorer with Focus (VBA)

    Try

    OK = Shell(callit, vbNormalFocus)

    to open Explorer in a normal (non-maximized) window, or

    OK = Shell(callit, vbMaximizedFocus)

    to open Explorer in a maximized window. More info about the available arguments can be obtained by clicking in the word Shell in the Visual Basic Editor and pressing F1 for help.

  5. #5
    3 Star Lounger
    Join Date
    Feb 2003
    Location
    Runcorn, Cheshire, United Kingdom
    Posts
    372
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Open Explorer with Focus (VBA)

    Many thanks, that's just what I wanted.
    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •