![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]() Hello I have written av vba code that creates tasks from mails and another code that finds via mail subject and deletes the task - but the second code that deletes doesnt work - it will not find the task with the items.find command Here is my code: Sub Done () Dim oExplorer As Outlook.Explorer Dim omail As Outlook.MailItem Dim oOldMail As Outlook.MailItem Dim StrSubject Dim mailsubject Set oExplorer = Application.ActiveExplorer If oExplorer.Selection.Item(1).Class = olMail Then Set oOldMail = oExplorer.Selection.Item(1) Set omail = oOldMail.Reply omail.SentOnBehalfOfName = " omail.To = oOldMail.SenderName omail.Subject = oOldMail.Subject omail.Recipients.Item(1).Resolve If omail.Recipients.Item(1).Resolved Then omail.Body = vbCrLf & "Hello test" & omail.Body omail.Display Else MsgBox "Error" & omail.Recipients.Item(1).Name End If Else MsgBox "This is not an email" Exit Sub End If mailsubject = "[Subject] =" & omail.Subject Call DeleteProjectTask End Sub Sub DeleteProjectTask() On Error Resume Next Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim olFolders As Outlook.Folders Dim bcmProjectTasksFolder As Outlook.MAPIFolder Dim existProjectTask As Outlook.TaskItem Set olApp = CreateObject("Outlook.Application") Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Session.Folders Set bcmProjectTasksFolder = objNS.GetDefaultFolder(olFolderTasks) Set existProjectTask = bcmProjectTasksFolder.Items.Find(mailsubject) If Not TypeName(existProjectTask) = "Nothing" Then existProjectTask.Delete Else MsgBox ("Cannot find task") End If End Sub |
Ads |
#2
|
|||
|
|||
![]()
mailsubject is local to the Done() procedure and must be passed to the
DeleteProjectTask() procedure, otherwise it will be a null string. A filter must have not only what you are looking for but the property to look in. The filter would have to look something like: bcmProjectTasksFolder.Items.Find("[Subject] = '" & mailsubject & "'") Those are single quotes in between the double quotes. If all this is running in Outlook VBA do not use CreateObject() in DeleteProjectTask(), just use the Application object you correctly used in Done(). -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "vbadude_sl" wrote in message ... Hello I have written av vba code that creates tasks from mails and another code that finds via mail subject and deletes the task - but the second code that deletes doesnt work - it will not find the task with the items.find command Here is my code: Sub Done () Dim oExplorer As Outlook.Explorer Dim omail As Outlook.MailItem Dim oOldMail As Outlook.MailItem Dim StrSubject Dim mailsubject Set oExplorer = Application.ActiveExplorer If oExplorer.Selection.Item(1).Class = olMail Then Set oOldMail = oExplorer.Selection.Item(1) Set omail = oOldMail.Reply omail.SentOnBehalfOfName = " omail.To = oOldMail.SenderName omail.Subject = oOldMail.Subject omail.Recipients.Item(1).Resolve If omail.Recipients.Item(1).Resolved Then omail.Body = vbCrLf & "Hello test" & omail.Body omail.Display Else MsgBox "Error" & omail.Recipients.Item(1).Name End If Else MsgBox "This is not an email" Exit Sub End If mailsubject = "[Subject] =" & omail.Subject Call DeleteProjectTask End Sub Sub DeleteProjectTask() On Error Resume Next Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim olFolders As Outlook.Folders Dim bcmProjectTasksFolder As Outlook.MAPIFolder Dim existProjectTask As Outlook.TaskItem Set olApp = CreateObject("Outlook.Application") Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Session.Folders Set bcmProjectTasksFolder = objNS.GetDefaultFolder(olFolderTasks) Set existProjectTask = bcmProjectTasksFolder.Items.Find(mailsubject) If Not TypeName(existProjectTask) = "Nothing" Then existProjectTask.Delete Else MsgBox ("Cannot find task") End If End Sub |
#3
|
|||
|
|||
![]() Thanks for your answer - but how can i pass the mailsubject to the delete procedure? I have tryed the call done(mailsubject) but this doesnt work "Ken Slovak - [MVP - Outlook]" wrote: mailsubject is local to the Done() procedure and must be passed to the DeleteProjectTask() procedure, otherwise it will be a null string. A filter must have not only what you are looking for but the property to look in. The filter would have to look something like: bcmProjectTasksFolder.Items.Find("[Subject] = '" & mailsubject & "'") Those are single quotes in between the double quotes. If all this is running in Outlook VBA do not use CreateObject() in DeleteProjectTask(), just use the Application object you correctly used in Done(). -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "vbadude_sl" wrote in message ... Hello I have written av vba code that creates tasks from mails and another code that finds via mail subject and deletes the task - but the second code that deletes doesnt work - it will not find the task with the items.find command Here is my code: Sub Done () Dim oExplorer As Outlook.Explorer Dim omail As Outlook.MailItem Dim oOldMail As Outlook.MailItem Dim StrSubject Dim mailsubject Set oExplorer = Application.ActiveExplorer If oExplorer.Selection.Item(1).Class = olMail Then Set oOldMail = oExplorer.Selection.Item(1) Set omail = oOldMail.Reply omail.SentOnBehalfOfName = " omail.To = oOldMail.SenderName omail.Subject = oOldMail.Subject omail.Recipients.Item(1).Resolve If omail.Recipients.Item(1).Resolved Then omail.Body = vbCrLf & "Hello test" & omail.Body omail.Display Else MsgBox "Error" & omail.Recipients.Item(1).Name End If Else MsgBox "This is not an email" Exit Sub End If mailsubject = "[Subject] =" & omail.Subject Call DeleteProjectTask End Sub Sub DeleteProjectTask() On Error Resume Next Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim olFolders As Outlook.Folders Dim bcmProjectTasksFolder As Outlook.MAPIFolder Dim existProjectTask As Outlook.TaskItem Set olApp = CreateObject("Outlook.Application") Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Session.Folders Set bcmProjectTasksFolder = objNS.GetDefaultFolder(olFolderTasks) Set existProjectTask = bcmProjectTasksFolder.Items.Find(mailsubject) If Not TypeName(existProjectTask) = "Nothing" Then existProjectTask.Delete Else MsgBox ("Cannot find task") End If End Sub |
#4
|
|||
|
|||
![]()
Why wouldn't it work? All it would be since mailsubject is a string value
would be something like this: Call Done(mailsubject) Sub Done(mailsubject As String) -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "vbadude_sl" wrote in message ... Thanks for your answer - but how can i pass the mailsubject to the delete procedure? I have tryed the call done(mailsubject) but this doesnt work |
#5
|
|||
|
|||
![]() It works now - thanx for great help "Ken Slovak - [MVP - Outlook]" wrote: Why wouldn't it work? All it would be since mailsubject is a string value would be something like this: Call Done(mailsubject) Sub Done(mailsubject As String) -- Ken Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "vbadude_sl" wrote in message ... Thanks for your answer - but how can i pass the mailsubject to the delete procedure? I have tryed the call done(mailsubject) but this doesnt work |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to delete overdue tasks/reminders? | jon | Outlook - General Queries | 1 | August 3rd 06 05:53 PM |
New message To, CC, BCC and Subject fields don't accept 'delete' | [email protected] | Outlook - General Queries | 3 | May 25th 06 08:34 PM |
Can I use the rules wizard to delete email with no subject line? | SPJarvis70 | Outlook - Installation | 0 | April 20th 06 09:55 PM |
User cannot edit or delete tasks | Micheline | Outlook - Installation | 0 | February 15th 06 11:35 PM |
Date: and Subject: Can I delete/hide them? | Richelle | Outlook - General Queries | 4 | February 7th 06 03:57 PM |