Jeg smider den op alligevel, det kan være der er nogen andre der kan få glæde af den. :-)
Løsningen forudsætter:
1. Outlook er startet.
2. Der er en liste af opgaver i det aktive Excelark, sat op som
skrevet ovenfor.
Bemærk:
- Kolonne D bruges til at indeholde et unikt "EntryID" for den enkelte task, så man undgår at oprette den samme opgave flere gange. Skjul Kolonne D hvis du ikke gider se på den.
Følgende kode copy/pastes ind i et Excel kodemodul:
--------------------------
Public Sub GetOutlookTasks()
Dim OlApp As Outlook.Application
Set OlApp = GetObject(, "Outlook.Application")
Dim OlNS As Outlook.NameSpace
Set OlNS = OlApp.GetNamespace("MAPI")
Dim OlTasks As Outlook.MAPIFolder
Set OlTasks = OlNS.GetDefaultFolder(olFolderTasks)
Dim i As Integer
For i = 1 To OlTasks.Items.Count
ThisWorkbook.ActiveSheet.Cells(i, 1) = OlTasks.Items(i).Subject
ThisWorkbook.ActiveSheet.Cells(i, 2) = OlTasks.Items(i).StartDate
ThisWorkbook.ActiveSheet.Cells(i, 3) = OlTasks.Items(i).DueDate
ThisWorkbook.ActiveSheet.Cells(i, 4) = OlTasks.Items(i).EntryID
Next i
' Luk og sluk
Set OlApp = Nothing
Set OlTasks = Nothing
End Sub
Public Sub CreateOutlookTasks()
On Error GoTo Fejl
Dim OlApp As Outlook.Application
Set OlApp = GetObject(, "Outlook.Application")
Dim OlNS As Outlook.NameSpace
Set OlNS = OlApp.GetNamespace("MAPI")
Dim OlTasks As Outlook.MAPIFolder
Set OlTasks = OlNS.GetDefaultFolder(olFolderTasks)
Dim myOlTask As Outlook.TaskItem
Dim rowCount As Integer
Dim colCount As Integer
Dim maxRows As Integer
Dim i As Integer
Dim j As Integer
maxRows = ActiveSheet.[A1].CurrentRegion.Rows.Count
For i = 1 To maxRows
If Cells(i, 4) = "" Then 'Task does not exist
Set myOlTask = OlTasks.Items.Add(olTaskItem)
With myOlTask
.Subject = Cells(i, 1)
.StartDate = Cells(i, 2)
.DueDate = Cells(i, 3)
.Save
End With
Else ' Task exists already
' Find task in Outlook tasklist
For j = 1 To OlTasks.Items.Count
If OlTasks.Items(j).EntryID = Cells(i, 4) Then ' Task Found
With OlTasks.Items(j) 'Update task
.Subject = Cells(i, 1)
.StartDate = Cells(i, 2)
.DueDate = Cells(i, 3)
.Save
End With
End If
Next j
End If
Next i
'MsgBox i - 1 & " tasks oprettet i Outlook"
' Luk og sluk
Set OlApp = Nothing
Set OlTasks = Nothing
Set OlNS = Nothing
Set myOlTask = Nothing
'Refresh
GetOutlookTasks
Exit Sub
Fejl:
MsgBox "Der opstod en fejl. Noter fejlen og spørg en eller anden på
www.eksperten.dk :-) "
End Sub
--------------------------