Home > Back-end >  outlook VBA to Loop through all tasks within all the task folders
outlook VBA to Loop through all tasks within all the task folders

Time:08-15

I have this Outlook VBA code that can loop through all the folders and debug their names. I can get the default folder for the task Set ObjTaskFolder = ObjNS.GetDefaultFolder(olFolderTasks). but the problem is I have two task folders and I need all the items(Tasks) within these folders.

I don't want to check all the folder items with .class=oltask so I am looking for a way to evaluate at folder level.

    Set ObjNS = Application.GetNamespace("MAPI")            
    
    For f = 1 To ObjNS.Folders(1).Folders.Count
    Debug.Print ObjNS.Folders(1).Folders(f)
        If (ObjNS.Folders(1).Folders(f).Class = olTask) Then
            'Task folder

        End If
    Next f
    

I am looking for a way to evaluate the folders, for the task folder only and then loop through all the item in within?

CodePudding user response:

Check that the MAPIFolder.DefaultItemType property is OlItemType.olTaskItem (=3) or the MAPIFolder.DefaultMessageClass property is "IPM.Task".

  • Related