A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Delete tasks from mail subject



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 27th 07, 11:42 AM posted to microsoft.public.outlook.program_vba
vbadude_sl
external usenet poster
 
Posts: 1
Default Delete tasks from mail subject


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  
Old February 27th 07, 04:57 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Delete tasks from mail subject

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  
Old February 28th 07, 09:51 AM posted to microsoft.public.outlook.program_vba
vbadude_sl
external usenet poster
 
Posts: 2
Default Delete tasks from mail subject


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  
Old February 28th 07, 03:06 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Delete tasks from mail subject

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  
Old March 1st 07, 03:46 PM posted to microsoft.public.outlook.program_vba
vbadude_sl
external usenet poster
 
Posts: 2
Default Delete tasks from mail subject


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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
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


All times are GMT +1. The time now is 08:49 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.