-
I'm running another program using the shell command. Then I call the AppActivate command. But it gives a runtime error saying that the program isn't loaded up yet. The program probably is taking a long time to load. Is there a way to delay or wait until the program is completely loaded?
-
FindWindow API
It is a good practice to find the specific window before you use the AppActivate function.
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_SHOWNORMAL = 1
Dim xhwnd&
xhwnd = FindWindow(0&, <Your Application Window Title>)
If xhwnd <> 0 Then
AppActivate <Your Application Window Title>
xhwnd = ShowWindow(xhwnd, SW_SHOWNORMAL)
End
End If
End If
-
FYI
I just want to add on to one more thing.
You don't have to provide the entire application's title when you are using "AppActivate" method. You can provide the first 5 letters or less. It just need a close match.
When you use "FindWindow", you must provide the exact application title. It has to be an exact match or spelling.