Vba Code
Use VBA To Reset Task Due Dates in Outlook
February 5, 2009 by Ty Anderson · 9 Comments
There was an earlier version of this post. It had more words and as it went on and on about how I track damn near everything in Outlook. It’s true. Everything. If I don’t track something I want to do or have to do as an Outlook task, it won’t get done.
I deleted that post by accident as I thought I was deleting something else. As it turns out, the wrong Window had the focus when I hit the Delete button and I deleted this post. Dammit!
Anyways, I always fall way behind on the deadlines I set for my tasks. So each Monday morning, I set the deadlines to a week from the current day.
Here is the VBA code to achieve this.
Sub ResetTaskDeadlines() Dim ns As NameSpace Dim fld As Folder Dim task As TaskItem Dim items As Outlook.items Dim rest As Outlook.items Dim filterSQL As String Set ns = Application.GetNamespace("MAPI") Set fld = ns.GetDefaultFolder(olFolderTasks) Set items = fld.items filterSQL = "@SQL=" & """http://schemas.microsoft.com/mapi/id/" filterSQL = filterSQL & "{00062003-0000-0000-C000-000000000046}/" filterSQL = filterSQL & "81010003""" & " <> 2" Set rest = items.Restrict("[Status] <> 'Completed'") For Each task In rest ''UNCOMMENT THE OPTION YOU WANT TO USE ''task.DueDate = "1/1/4501" 'Set to NO Due Date ''task.DueDate = task.DueDate + 7 ' Set to 7 days from current due date task.DueDate = today() + 7 'Set to a week from today ''task.DueDate = FirstDayOfNextMonth ' Set to first day of next month 'task.Save Next End Sub Function FirstDayOfNextMonth() As Date Dim d As Date d = Date FirstDayOfNextMonth = DateSerial(Year(d), Month(d) + 1, 1) End Function
I pretty much use VSTO to build Outlook add-ins professionally. But for quick personally useful scripts like this, VBA still reins.
