Hi!
The code below converts incoming mail in Outlook to a task and moves the task to a SharePoint-list. So far so good
When the task appears in the SharePoint-list it should be given a status (Not Started, Started, Completed) automatically. This is a requirement to make the line visible when connecting to the SharePoint-list through a browser.
My problem seems to be that the task is moved into the SharePoint-list without any status what so ever, thus not visible. The solution is to manually click on "Tasks" in Outlook and then return by clicking the SharePoint-list in Outlook. Then the task changes from no status at all to "Not Started".
Is there any way to have the task set to "Not Started" as default behaviour automatically - perhaps by adding some code to the macro?
Sub ConvertMailtoTask(Item As Outlook.MailItem)
Dim objTask As Outlook.TaskItem
Set objTask = Application.CreateItem(olTaskItem)
'move this up here just to get it out of the way
Set SPSFolder = GetFolderPath("SharePoint-lists\Any_given_folder")
' this creates and saves the task
With objTask
.Subject = Item.Subject
.StartDate = Item.ReceivedTime
.Body = Item.Body
.Save
End With
' this can go right before 'end with' (if so remove ojbtask from it)
objTask.Move SPSFolder
' this goes last, before the sub ends
Set objTask = Nothing
End Sub
Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function
GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function
The code below converts incoming mail in Outlook to a task and moves the task to a SharePoint-list. So far so good
When the task appears in the SharePoint-list it should be given a status (Not Started, Started, Completed) automatically. This is a requirement to make the line visible when connecting to the SharePoint-list through a browser.
My problem seems to be that the task is moved into the SharePoint-list without any status what so ever, thus not visible. The solution is to manually click on "Tasks" in Outlook and then return by clicking the SharePoint-list in Outlook. Then the task changes from no status at all to "Not Started".
Is there any way to have the task set to "Not Started" as default behaviour automatically - perhaps by adding some code to the macro?
Sub ConvertMailtoTask(Item As Outlook.MailItem)
Dim objTask As Outlook.TaskItem
Set objTask = Application.CreateItem(olTaskItem)
'move this up here just to get it out of the way
Set SPSFolder = GetFolderPath("SharePoint-lists\Any_given_folder")
' this creates and saves the task
With objTask
.Subject = Item.Subject
.StartDate = Item.ReceivedTime
.Body = Item.Body
.Save
End With
' this can go right before 'end with' (if so remove ojbtask from it)
objTask.Move SPSFolder
' this goes last, before the sub ends
Set objTask = Nothing
End Sub
Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function
GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function