Tasks Collection Object

Description

A collection of Task objects that represent all the tasks currently running on the system.

Using the Tasks Collection

Use the Tasks property to return the Tasks collection. The following example determines whether Microsoft Excel is running. If Microsoft Excel is already running, this example switches to it and maximizes it; otherwise, the example starts it.

If Tasks.Exists("Microsoft Excel") = True Then
    Tasks("Microsoft Excel").Activate
    Tasks("Microsoft Excel").WindowState = wdWindowStateMaximize
Else
    Shell "C:\MSOffice\Excel\Excel.exe"
End If
Use the Shell function to run an executable program and add the program to the Tasks collection.

Use Tasks(index), where index is the application name or the index number, to return a single Task object. The following example opens and resizes the application window for the first visible task in the Tasks collection.

With Tasks(1)
    If .Visible = True Then
        .Activate
        .Width = 400
        .Height = 200
    End If
End With
The following example restores the Calculator application window if the application is in the Tasks collection.

If Tasks.Exists("Calculator") = True Then
    Tasks("Calculator").WindowState = wdWindowStateNormal
End If
Properties

Application property, Count property, Creator property, Parent property.

Methods

Exists method, ExitWindows method, Item method.