Class Tasks (Word VBA)

A collection of Task objects that represents all the tasks currently running on the system. To use a Tasks class variable it first needs to be instantiated, for example


Dim tsks as Tasks
Set tsks = Tasks

For Each

Here is an example of processing the Tasks items in a collection.


Dim tsk As Task
For Each tsk In Tasks
	
Next tsk

Count

Returns a Long that represents the number of tasks in the collection.


Dim lngCount As Long
lngCount = Tasks.Count

Exists

Determines whether the specified task exists. Returns True if the task exists.

Exists (Name)

Name: The name of the task.


If Tasks.Exists("Calculator") = False Then 
 Shell "Calc.exe" 
Else 
 Tasks("Calculator").Activate 
End If 
Tasks("Calculator").WindowState = wdWindowStateNormal

ExitWindows

Closes all open applications, quits Microsoft Windows, and logs the current user off.

This method does not save changes to open Microsoft Word documents; however, it does prompt you to save changes to open documents in other Windows-based applications.


Documents.Save NoPrompt:=True, _ 
 OriginalFormat:=wdOriginalDocumentFormat 
Tasks.ExitWindows

Item

Returns an individual Task object in a collection.

Item (Index)

Index: The individual object to be returned. Can be a Long indicating the ordinal position or a String representing the name of the individual object.


Dim tsk As Task
Set tsk = Tasks(Index:=1)