saban
02-07-2008, 11:12 AM
Guys any ideas how task is created from mail in other mailbox then default one???
I have two mailboxes and when i run this macro it is creating task in the default mailbox even though the email which task is created from is in another mailbox
Dim i As Integer
Dim datum As Date
Dim olTask As Outlook.TaskItem
' Using object rather than MailItem, so that it can handle posts, meeting requests, etc as well
Dim olItem As Object
Dim olExp As Outlook.Explorer
Dim fldCurrent As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Set olApp = Outlook.CreateObject("Outlook.Application")
Set olTask = olApp.CreateItem(olTaskItem)
Set olExp = olApp.ActiveExplorer
Set fldCurrent = olExp.CurrentFolder
Dim cntSelection As Integer
cntSelection = olExp.Selection.count
If cntSelection = 0 Then
MsgBox "please select at least 1 mail"
Exit Sub
End If
If cntSelection >= 2 Then
Dim Response As VbMsgBoxResult
Response = MsgBox("Please note that 1 task will be created with 2 or more mails attached inside" & _
vbCrLf & "do you want to continue ?", vbQuestion + vbYesNo)
If Response = vbNo Then
Exit Sub
End If
End If
For i = 1 To cntSelection
Set olItem = olExp.Selection.Item(i)
olTask.Attachments.Add olItem
olTask.Subject = olItem.Subject
' olItem.Delete
Next
' olTask.Display
datum = UserForm1.Calendar1
' Set the due date for today
datum = UserForm1.Calendar1.Value
olTask.DueDate = datum
' Set the reminder for 3 hours from now
If datum <> Now Then
olTask.ReminderSet = False
' olTask.ReminderTime = DateAdd("h", 3, Now)
End If
' Saving the task item, so that in case I close it, I won't lose the items which were deleted after being attached to the task
olTask.Save
Unload Me
olTask.Display
olTask.Save
I have two mailboxes and when i run this macro it is creating task in the default mailbox even though the email which task is created from is in another mailbox
Dim i As Integer
Dim datum As Date
Dim olTask As Outlook.TaskItem
' Using object rather than MailItem, so that it can handle posts, meeting requests, etc as well
Dim olItem As Object
Dim olExp As Outlook.Explorer
Dim fldCurrent As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Set olApp = Outlook.CreateObject("Outlook.Application")
Set olTask = olApp.CreateItem(olTaskItem)
Set olExp = olApp.ActiveExplorer
Set fldCurrent = olExp.CurrentFolder
Dim cntSelection As Integer
cntSelection = olExp.Selection.count
If cntSelection = 0 Then
MsgBox "please select at least 1 mail"
Exit Sub
End If
If cntSelection >= 2 Then
Dim Response As VbMsgBoxResult
Response = MsgBox("Please note that 1 task will be created with 2 or more mails attached inside" & _
vbCrLf & "do you want to continue ?", vbQuestion + vbYesNo)
If Response = vbNo Then
Exit Sub
End If
End If
For i = 1 To cntSelection
Set olItem = olExp.Selection.Item(i)
olTask.Attachments.Add olItem
olTask.Subject = olItem.Subject
' olItem.Delete
Next
' olTask.Display
datum = UserForm1.Calendar1
' Set the due date for today
datum = UserForm1.Calendar1.Value
olTask.DueDate = datum
' Set the reminder for 3 hours from now
If datum <> Now Then
olTask.ReminderSet = False
' olTask.ReminderTime = DateAdd("h", 3, Now)
End If
' Saving the task item, so that in case I close it, I won't lose the items which were deleted after being attached to the task
olTask.Save
Unload Me
olTask.Display
olTask.Save