AppActivate Statement
Activates an application window — gives it the focus.
Syntax
AppActivate title[, wait]
Arguments
- title: String expression or numeric Shell task ID naming the
window to activate. String matching follows VB6 rules: the first
window whose title begins with
titlewins; if none, one whose title ends withtitle. Comparisons are case-insensitive. - wait (optional): Boolean. When
True, activation is deferred until the calling application itself has the focus;False(the default) activates immediately.
Remarks
- Error 5: Raises "Invalid procedure call or argument" when no open
window matches
title. - Task IDs: A numeric
title— usually the return value ofShell— selects the window of that task. - Headless platforms: Where no window facility exists (CI machines, WASM), the request is logged and the call succeeds so programs stay runnable.
Examples
Activating Notepad before sending keystrokes
AppActivate "Notepad"
SendKeys "Hello, world"
Using a Shell task ID
Dim taskId As Double
taskId = Shell("CALC.EXE", vbNormalFocus)
AppActivate taskId
See Also
Shellfunction (run a program, returning its task ID)SendKeysstatement (send keystrokes to the active window) Reference