• Open Explorer with Focus (VBA)

    Author
    Topic
    #432363

    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 ?

    Viewing 0 reply threads
    Author
    Replies
    • #1014064

      What code are you using at present?

      • #1014084

        Hi Hans,
        The code I’m using is

        MyPath = "C:pipeximages"
        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 

        The value of “callit” in the Shell command is

        explorer /n, "C:pipeximages"

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

        • #1014086

          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.

    Viewing 0 reply threads
    Reply To: Open Explorer with Focus (VBA)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: