Search, Results and modifying subject

  • Thread starter Thread starter Ptit Dark
  • Start date Start date
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
 
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
-
 
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
-
 
Back
Top