README.md

December 4, 2022 ยท View on GitHub

Add Outlook Tasks

Description

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.

More Info

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.

Submitted On
ByTroy Blake
LevelBeginner
User Rating4.6 (32 globes from 7 users)
CompatibilityVB 5.0, VB 6.0
CategoryMicrosoft Office Apps/VBA
WorldVisual Basic
Archive File

Source Code

'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