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 - General Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VBA Code to Delete an Email After it is Processed by VBA



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 7th 10, 03:25 AM posted to microsoft.public.outlook
robboll
external usenet poster
 
Posts: 5
Default VBA Code to Delete an Email After it is Processed by VBA

The following code is a hybrid from several internet sources. Mostly
from this forum.

I have an application that starts an email thread and assigns a Task
ID like: TID(123) This is the Subject

When an email is received with "TID(###)" somewhere in the subject, a
native rule then copies it to a subfolder under the CurrentFolder
called 'TID'.

The following code works to copy the email in msg format to its
associated network directory, but the email remains in the
subfolders.

What I am trying to accomplish is to automatically delete the email
after it is processed by VBA.
Is there a simple method of doing this?


Sub CopyEmailToProjectFolder()
Dim OL As Application
Dim NmeSpace As NameSpace
Dim strConnection
Dim mTID

Set OL = CreateObject("Outlook.Application")
Set NmeSpace = OL.GetNamespace("MAPI")
Set Inbx = NmeSpace.GetDefaultFolder(6)
Set fldr = Application.ActiveExplorer.CurrentFolder.Folders(" TID")
For Each itm In fldr.Items
subtxt = Trim(itm.Subject)

'SubTxt = CleanString(SubTxt) 'removes characters that cannot be
part of filename
subtxt = Replace(subtxt, "_", "")
subtxt = Replace(subtxt, "??", "'")
subtxt = Replace(subtxt, "`", "'")
subtxt = Replace(subtxt, "{", "(")
subtxt = Replace(subtxt, "[", "(")
subtxt = Replace(subtxt, "]", ")")
subtxt = Replace(subtxt, "}", ")")
subtxt = Replace(subtxt, "/", "-")
subtxt = Replace(subtxt, "\", "-")
subtxt = Replace(subtxt, ":", "")
subtxt = Replace(subtxt, ",", "")
'Cut out invalid signs.
subtxt = Replace(subtxt, "*", "'")
subtxt = Replace(subtxt, "?", "")
subtxt = Replace(subtxt, """", "'")
subtxt = Replace(subtxt, "", "")
subtxt = Replace(subtxt, "", "")
subtxt = Replace(subtxt, "|", "")
mTID = Mid(Mid(subtxt, InStr(1, subtxt, "TID(") + 4, 8), 1, InStr
(1, Mid(subtxt, InStr(1, subtxt, "TID(") + 4, 8), ")") - 1)

'====== SQL Connection String to Get full Directory Path from the
TID ============
Dim Connection
Dim ConnString
Dim Recordset
Dim SQL
Dim mTopic
Dim mPath

ConnString = "DRIVER={SQL
Server};Server=MyServer;Database=MyReport;Trusted_ Connection=True;"

SQL = "SELECT [TopicID],[Path] FROM [MyReport].[dbo].[uvw_TIDPath]
WHERE rtrim([TopicID]) = " & mTID

Set Connection = CreateObject("ADODB.Connection")
Set Recordset = CreateObject("ADODB.Recordset")

Connection.Open ConnString
Recordset.Open SQL, Connection

If Recordset.EOF Then
Response.Write ("No records returned.")
Else
'if there are records then loop through the fields
Do While Not Recordset.EOF
mTopic = Recordset("TopicID")
mPath = Recordset("Path") & "\"
Recordset.MoveNext
Loop
End If

'close the connection and recordset objects to free up resources
Recordset.Close
Set Recordset = Nothing
Connection.Close
Set Connection = Nothing

dirname = mPath

' fnme = DirName & subtxt & ".msg"
If itm.Class = olMail Then
itm.SaveAs fnme, olMSG
End If

'Save attachments if they exist in the item
If itm.Attachments.Count 0 Then
For Each Attmt In itm.Attachments
fnme = dirname & Attmt.DisplayName
On Error Resume Next
x = Dir(fnme) 'Check if file exists
If x = "" Then
Attmt.SaveAsFile fnme
End If
Next
End If

Next
End Sub
Ads
  #2  
Old January 7th 10, 08:53 AM posted to microsoft.public.outlook
Bob Bollinger
external usenet poster
 
Posts: 2
Default VBA Code to Delete an Email After it is Processed by VBA

Found my own solution:
simply put: itm.Delete after the last End If

Cheers!

---
frmsrcurl: http://msgroups.net/microsoft.public...ocessed-by-VBA
  #3  
Old January 8th 10, 12:55 AM posted to microsoft.public.outlook
Bob Bollinger
external usenet poster
 
Posts: 2
Default VBA Code to Delete an Email After it is Processed by VBA

Grrrrr! This doesn't work all the time!!! Have no idea why. Each itm is deleted according to the code!

---
frmsrcurl: http://msgroups.net/microsoft.public...ocessed-by-VBA
  #4  
Old January 8th 10, 12:59 AM posted to microsoft.public.outlook
ROBBOLL
external usenet poster
 
Posts: 2
Default VBA Code to Delete an Email After it is Processed by VBA

Grrrrrr! Doesn't work every time. Is there a way to force a delete after
processing?

"Bob Bollinger" wrote:

Found my own solution:
simply put: itm.Delete after the last End If

Cheers!

---
frmsrcurl: http://msgroups.net/microsoft.public...ocessed-by-VBA
.

  #5  
Old January 8th 10, 02:41 PM posted to microsoft.public.outlook
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default VBA Code to Delete an Email After it is Processed by VBA

Programming questions should be posted to the programming groups. You might
try microsoft.public.outlook.program_vba.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"ROBBOLL" wrote in message
...
Grrrrrr! Doesn't work every time. Is there a way to force a delete after
processing?

"Bob Bollinger" wrote:

Found my own solution:
simply put: itm.Delete after the last End If

Cheers!

---
frmsrcurl:
http://msgroups.net/microsoft.public...ocessed-by-VBA
.


 




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
delete email once it has been replyed to in outlook, through VBA code jinjay Outlook and VBA 5 February 23rd 09 05:20 PM
Meeting response not processed Amedee Van Gasse Outlook - Calandaring 4 January 22nd 09 10:37 AM
How are Meeting Requests Processed? Jason C. Lamb Outlook - Calandaring 4 March 2nd 08 11:16 AM
code to delete all contacts [email protected] Outlook - General Queries 1 January 15th 08 07:53 AM
email extension can't be processed what pgm. is associated with it paul Masson Outlook Express 5 November 11th 06 08:15 PM


All times are GMT +1. The time now is 08:12 AM.


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