VBA - Creating a custom view RRS feed

  • Question

  • Hi all.

    Can anyone help with code for creating a custom view for a folder using VBA?

    I need code that will Create a custom view and specify what columns/fields are in the view.

    Any help is very much appreciated.



    Outlook 2010
    • Edited by IAMDAN Friday, June 19, 2015 9:12 AM
    Friday, June 19, 2015 9:11 AM

All replies


    To get started, you need to use the Add method of the views collection to create your custom view.  For example.

    Sub CreateView() 
     'Creates a new view 
     Dim objName As Outlook.NameSpace 
     Dim objViews As Outlook.Views 
     Dim objNewView As Outlook.View 
     Set objName = Application.GetNamespace("MAPI") 
     Set objViews = objName.GetDefaultFolder(olFolderInbox).Views 
     Set objNewView = objViews.Add(Name:="New Table", _ 
     ViewType:=olTableView, SaveOption:=olViewSaveOptionThisFolderEveryone) 
    End Sub

    Use the methods (Add, Insert, Remove) of the new view's ViewFields object to determine the columns displayed. For each ViewField object in your view Use the ColumnFormat property to access the ColumnFormat object representing the display properties associated with the view field.

    You have to Save your new view and Apply it.

    You will need the ViewXMLSchemaName to manipulate the Viewfield objects.  See for a description of referencing properties by namespace.  Outlookspy and MFCMapi will likely be very helpful to you.

    When it comes to customizing views, my own experience is that it is an iterative process that requires trial and error.  You'll learn a lot along the way.

    Friday, June 19, 2015 11:37 AM
  • Views are defined and customized using the View object's XML property. The XML property allows you to create and set a customized XML schema that defines the various features of a view. There is no need to create a new views, you can customize existing ones using the XML property.

    To programmatically add a custom field to a view, use the Add method of the ViewFields object. This is the recommended way to dynamically change the view over setting the XML property of the View object.

    There are a variety of different view types that provide the flexibility needed to create and maintain your important data.

     - The table view type (olTableView) allows you to view data in a simple field-based table.

     - The Calendar view type (olCalendarView) allows you to view data in a calendar format.

     - The card view type (olCardView) allows you to view data in a series of cards. Each card displays the information contained by the item and can be sorted.

     -The icon view type (olIconView) allows you to view data as icons, similar to a Windows folder or explorer. 

    1.  - The timeline view type (olTimelineView) allows you to view data as it is received in a customizable linear time line.

    To obtain a View object for the view of the current Explorer, use Explorer.CurrentView instead of the CurrentView property of the current Folder object returned by Explorer.CurrentFolder.

    To determine how the XML should be structured when creating views, you can create a view by using the Outlook user interface and then you can retrieve the XML property for that view.

    Friday, June 19, 2015 11:43 AM