Class Microsoft.VisualBasic.Interaction Syntax AppActivate({ title | processID })
title (required if processID missing; String) The name of the application as currently shown in the application's title bar
processID (required if title missing; Integer) The task ID returned from the Shell function Description The AppActivate procedure activates a window based on its caption or process ID. Usage at a Glance When activating an application by title, AppActivate performs a case-insensitive search on all top-level windows for a match. If an exact match is found, the window is activated. If no match is found, then the window captions are searched for a prefix match (title matches the beginning of the window caption). For example, the title "My Program" matches "My Program-MyDocument.xyz." If a prefix match is found, the window is activated. If multiple prefix matches are found, there is no way to predict which matching window will be activated. The window state (Maximized, Minimized, or Normal) of the activated application is not affected by AppActivate. If a matching application cannot be found, an error occurs. AppActivate searches only top-level windows. The Shell function returns an Integer value representing the process ID of the new application. This value can be passed directly to the AppActivate procedure. Several years ago, Microsoft changed their recommended method of naming window captions. The new standard places the document name first, followed by the application name, as in "Untitled.doc - Microsoft Word." This can make it more difficult to locate a window by caption. AppActivate is often used to give the focus to a particular window before keystrokes are sent to it using the SendKeys statement. Example Public Function ActivateAppByTitle(ByVal theTitle As String) _ As Boolean ' ----- Return success flag. On Error GoTo ErrorHandler AppActivate(theTitle) Return True ErrorHandler: MsgBox ("Application " & theTitle & " could not be activated.") Return False End Function Version Differences In VB 6, AppActivate has an optional Boolean parameter, wait, which postpones activation until the local program has the focus. In .NET, wait is not supported. See Also SendKeys Statement, Shell Function |