AppActivate Method
Activates an application window.
Namespace
Microsoft.VisualBasic
Assembly
Microsoft.VisualBasic.dll
Syntax
Public Sub AppActivate (title As String)
Public Sub AppActivate (processId As Integer)
Parameters
| Name | Type | Description |
|---|---|---|
| title | String | The title of the window to activate. Partial titles are allowed. |
| processId | Integer | The ID of the process that owns the window to activate. |
Return Value
This method does not return a value.
Remarks
- The method sends a window‑activate message to the target application. If multiple windows match the title, the first match is used.
- Use
processIdwhen you have the exact process ID; this avoids ambiguity. - Throws
ArgumentExceptionif the title does not match any visible window. - Works only on Windows platforms.
Exceptions
| Exception | Condition |
|---|---|
ArgumentException | No window with the specified title is found. |
ArgumentOutOfRangeException | The processId does not correspond to an existing process. |
Example
Activate Notepad using its window title:
Imports Microsoft.VisualBasic
Module Example
Sub Main()
' Launch Notepad
Process.Start("notepad.exe")
System.Threading.Thread.Sleep(500) ' wait for the window to appear
' Activate the Notepad window
Interaction.AppActivate("Untitled - Notepad")
End Sub
End Module