How to refocus back onto excel after opening an application

Eyeson15

Board Regular
Joined
Apr 30, 2015
Messages
201
Good morning,

I have an opening vba that checks if a program is open and if not it will open it for me:

Code:
Sub CheckProg()
    
    Dim objList As Object, objType As Object, strObj$
    strObj = "terminal.exe"
    Set objType = GetObject("winmgmts:").ExecQuery("select * from win32_process where name='" & strObj & "'")
    If objType.Count = 0 Then

    Dim x As Variant
    Dim Path As String

    Path = "C:\Program Files (x86)\Oolah41\terminal.exe"

    x = Shell(Path, vbMinimizedFocus)
    
    Application.Wait (Now + TimeValue("0:00:05"))
    End If
End Sub

The program is minimized upon opening and it then waits 5 seconds (as you can see in the code above) before the next macro is automatically run which calculates few things and shows me the result in a msgbox.

The problem is the msgbox is hidden UNTIL I physically CLICK onto the excel window/program.

I have tried:
Windows("ThisExcel.xlsm").Activate
ThisWorkbook.Activate

BUT nothing seems to actually refocus back onto the excel program so its back up on top of all my other programs and then show me the msgbox with the important results.

I have also tried modal msgbox alert
MsgBox "Value of your input is XXXX", vbSystemModal, "IMPORTANT"
and that still doesn't come forward to the top.

Any suggestions?

I need the msgbox to pop out infront of EVERYTHING.

Thank you
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi Eyeson15,
change this line
x = Shell(Path, vbMinimizedFocus)
to
x = Shell(Path, vbMinimizedNoFocus)

hope this helps
regards
 
Upvote 0
Hi Eyeson15,
change this line
x = Shell(Path, vbMinimizedFocus)
to
x = Shell(Path, vbMinimizedNoFocus)

hope this helps
regards


OMG!! It was that simple!!!
And I was literally crying on the keyboard....
You are better than google search
Thank you very much

James
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top