by Troy Blake (3 Submissions)
Category: Microsoft Office Apps/VBA
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (7 Votes)
Used to show and add new tasks to Outlook. Simple code to demo getting task list and also adding a new task in Outlook. Please vote.
Assumes
Create Reference to Outlook. Create a form, insert code. Also put a combobox on the form and name it cboTasklist. Load form at runtime to view current task list. Simple code to demo getting task list and also adding a new task. Not very useful as it is listed here, but you can see how you could change it to be a useful function. Please vote.
'Simple Outlook Task View/Add Code
'Troy Blake - Logan's Roadhouse, Inc.
Private Sub InitForm()
'Loads current task to dropdown, then adds
'a task for John Smith. John gets the task
'sent to him via Outlook.
Dim oApp as Outlook.Application
Dim oNspc as NameSpace
Dim oItm as TaskItem
Dim myItem as TaskItem
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")
For Each oItm in oNspc.GetDefaultFolder(olFolderTasks).Items
'Loop through all tasks and show subject
'in dropdown.
With Me.cboTasklist
.AddItem (oItm.Subject)
End With
Next oItm
oNspc.GetDefaultFolder(olFolderTasks).Items.Add
Set myItem = oApp.CreateItem(olTaskItem)
'Create a new task
With myItem
.Subject = "Subject"
.Assign = "Assign"
.Body = "Task Body"
.PercentComplete = 10
'Set due date for tomorrow
.DueDate = DateAdd("d",1,Date)
.ReminderSet = True
.ReminderTime = "9:00 AM"
'Outlook name of person to get task
.Recipients.Add "John Smith"
.Close (olSave)
End With
'Send the task (like email)
myItem.Send
Set myItem = Nothing
Set oItm = Nothing
Set oNspc = Nothing
Set oApp = Nothing
End Sub
Private Sub Form_Load()
'Call out sample sub at form load
InitForm
End Sub