Class Columns (Outlook VBA)

The class Columns represents the collection of Column objects in a Table object. To use a Columns class variable it first needs to be instantiated, for example


Dim clms as Columns
Set clms = AdvancedSearch.GetTable.Columns

For Each

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


Dim clm As Column
For Each clm In AdvancedSearch.GetTable.Columns
	
Next clm

Add

Adds the Column specified by Name to the Columns collection and resets the Table.

Columns.Add adds the specified Column to the end of the Columns collection for the Table, and resets the Table by moving the current row to just before the first row of the Table. If Columns.Add returns an error, it will not change the current row. Name can be an explicit built-in property name, or a property name referenced by namespace. It must be referenced as the name in the English locale. For more information on referencing properties by namespace, see Referencing Properties by Namespace. If you are adding a property which is an explicit built-in property in the object model, for example, Contact.FirstName, you must specify Name as the explicit built-in property name in English. For certain types of properties, the format used when adding these properties as columns affects how their values are expressed in the Table. For more information on property value representation in a Table, see Factors Affecting Property Value Representation in the Table and View Classes. If you are adding a custom property to a Table, referencing the property by the MAPI string namespace, you will have to explicitly append the type of the property to the end of the property reference. For example, to add the custom property MyCustomProperty, which has the type Unicode string, you will have to explicitly append the type 001f to the reference, resulting in: http://schemas.microsoft.com/mapi/string/{HHHHHHHH-HHHH-HHHH-HHHH-HHHHHHHHHHHH}/MyCustomProperty/0x0000001f, where {HHHHHHHH-HHHH-HHHH-HHHH-HHHHHHHHHHHH} represents the namespace GUID. Certain properties cannot be added to a Table using Columns.Add, including binary properties, computed properties, and HTML or RTF body content. For more information, see Unsupported Properties in a Table Object or Table Filter. While Items.SetColumns can be used to facilitate caching certain properties for extremely fast access to those properties of an Items collection, some properties are restricted from SetColumns. Since these restrictions do not apply to Columns.Add, the Table object is a less restrictive alternative than Items.

Add (Name)

Name: The name of the property that is being added as a column.


Sub AddColumns() 
 
 'Declarations 
 
 Dim Filter As String 
 
 Dim oRow As Outlook.Row 
 
 Dim oTable As Outlook.Table 
 
 Dim oFolder As Outlook.Folder 
 
 
 
 'Get a Folder object for the Inbox 
 
 Set oFolder = Application.Session.GetDefaultFolder(olFolderInbox) 
 
 
 
 'Define Filter to obtain items last modified after May 1, 2005 
 
 Filter = "[LastModificationTime] > '5/1/2005'" 
 
 'Restrict with Filter 
 
 Set oTable = oFolder.GetTable(Filter) 
 
 
 
 'Remove all columns in the default column set 
 
 oTable.Columns.RemoveAll 
 
 'Specify desired properties 
 
 With oTable.Columns 
 
 .Add ("Subject") 
 
 .Add ("LastModificationTime") 
 
 'PR_ATTR_HIDDEN referenced by the MAPI proptag namespace 
 
 .Add ("http://schemas.microsoft.com/mapi/proptag/0x10F4000B") 
 
 End With 
 
 
 
 'Enumerate the table using test for EndOfTable 
 
 Do Until (oTable.EndOfTable) 
 
 Set oRow = oTable.GetNextRow() 
 
 Debug.Print (oRow("Subject")) 
 
 Debug.Print (oRow("LastModificationTime")) 
 
 Debug.Print (oRow("http://schemas.microsoft.com/mapi/proptag/0x10F4000B")) 
 
 Loop 
 
End Sub

Class

Returns a constant in the OlObjectClass enumeration indicating the class of the Columns object. Here you can find possible values for OlObjectClass.


Dim oocsClass As OlObjectClass
oocsClass = AdvancedSearch.GetTable.Columns.Class

Count

Returns a Long representing the number of Column objects in the collection.


Dim lngCount As Long
lngCount = AdvancedSearch.GetTable.Columns.Count

Item

Obtains a Column object specified by Index.

Item (Index)

Index: A 1-based index value that can be either a Long representing the column index for the Columns collection or a String representing the Name of the Column.


Dim clm As Column
Set clm = AdvancedSearch.GetTable.Columns(Index:=1)

Remove

Removes the Column object specified by Index and resets the Table.

The Remove method resets the Table by moving the current row to just before the first row of the Table. If, however, an invalid Index has been specified, then it will not remove any column or reset the Table. Returns an error message if an invalid Index has been specified.

Remove (Index)

Index: A 1-based index value that can be either a Long representing the column index for the Columns collection or a String representing the Name of the Column.


Dim lngIndex As Long: lngIndex = 
AdvancedSearch.GetTable.Columns.Remove Index:=lngIndex

RemoveAll

Removes all the columns from the Columns collection and resets the Table.

RemoveAll resets the Table by moving the current row to just before the first row of the Table. After a call to RemoveAll, Columns.Count becomes zero (0).


Sub RemoveAllAndAddColumns() 
 
 'Declarations 
 
 Dim Filter As String 
 
 Dim oRow As Outlook.Row 
 
 Dim oTable As Outlook.Table 
 
 Dim oFolder As Outlook.Folder 
 
 
 
 'Get a Folder object for the Inbox 
 
 Set oFolder = Application.Session.GetDefaultFolder(olFolderInbox) 
 
 
 
 'Define Filter to obtain items last modified after May 1, 2005 
 
 Filter = "[LastModificationTime] > '5/1/2005'" 
 
 'Restrict with Filter 
 
 Set oTable = oFolder.GetTable(Filter) 
 
 
 
 'Remove all columns in the default column set 
 
 oTable.Columns.RemoveAll 
 
 'Specify desired properties 
 
 With oTable.Columns 
 
 .Add ("Subject") 
 
 .Add ("LastModificationTime") 
 
 'PR_ATTR_HIDDEN referenced by the MAPI proptag namespace 
 
 .Add ("http://schemas.microsoft.com/mapi/proptag/0x10F4000B") 
 
 End With 
 
 
 
 'Enumerate the table using test for EndOfTable 
 
 Do Until (oTable.EndOfTable) 
 
 Set oRow = oTable.GetNextRow() 
 
 Debug.Print (oRow("Subject")) 
 
 Debug.Print (oRow("LastModificationTime")) 
 
 Debug.Print (oRow("http://schemas.microsoft.com/mapi/proptag/0x10F4000B")) 
 
 Loop 
 
End Sub

Session

Returns the NameSpace object for the current session.

The Session property and the Application.GetNamespace method can be used interchangeably to obtain the NameSpace object for the current session. Both members serve the same purpose. For example, the following statements perform the same function: