Search, Results and modifying subject

P

Ptit Dark

Hi everyone,

I look for some emails that I want to erase definitly. 'Cause vba cannot
perform a shift+delete, I try to find a workaround.
So I want to change the subject by a value (here it's date and time given by
Now() function), then delete. Please see the code below.
It deletes email no problem... it changes the subject, sometimes... like
once for an hundred emails.
I just thought it's a matter of speed. So if you remove the comments, I use
a loop to make the subject changes until it changes and it causes an infinite
loop.

Dim oSearch As Outlook.Search, oResult As Outlook.Results
Dim i As Integer, iNbEmail As Integer, sDelete As String
blnSearchComp = False
sDelete = Now
Set oSearch = Application.AdvancedSearch("Sent Items", "my search params")
While blnSearchComp = False
DoEvents
Wend

Set oResult = oSearch.Results
iNbEmail = oResult.Count
For i = 1 To iNbEmail
' While oResult.Item(i).Subject <> sDelete
oResult.Item(i).Subject = sDelete
' DoEvents
' Wend
oResult.Item(i).Delete
Next

I need help. Badly !
I know I must do something wrong, but I can't figure out what.

Thx
 
D

Dmitry Streblechenko

You are not calling Save:

For i = 1 To iNbEmail
set Item = oResult.Item(i).
Item.Subject = sDelete
Item.Delete
Next


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
P

Ptit Dark

It worked !! Thx a lot

Dmitry Streblechenko said:
You are not calling Save:

For i = 1 To iNbEmail
set Item = oResult.Item(i).
Item.Subject = sDelete
Item.Delete
Next


--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top