Hi,
I have a code which can delete mail items from outlook express from inbox folder if a certain mail has a particular subject line.
My problem is when i try to run this same code for deleting mails from the deleted items folder making the neccessary change in the macro i get an error.
Can anyone please help on this:-
the code is as below
many thanks in advance
Regards,
Premanshu
I have a code which can delete mail items from outlook express from inbox folder if a certain mail has a particular subject line.
My problem is when i try to run this same code for deleting mails from the deleted items folder making the neccessary change in the macro i get an error.
Can anyone please help on this:-
the code is as below
Code:
Sub DeleteMail()
Dim out_app As Outlook.Application
Dim folders As Outlook.Namespace
Dim myfolder As Outlook.MAPIFolder
Dim mails_itm As MailItem
Set start_fm = Range("a1")
Set out_app = New Outlook.Application
Set folders = out_app.GetNamespace("mapi")
Set myfolder = folders.GetDefaultFolder(olFolderInbox)
'''''this below line i'll use when i'll try to delete mail from deleted items
'Set myfolder = folders.GetDefaultFolder(olFolderDeletedItems)
For Each mails_itm In myfolder.Items
If mails_itm.Subject = "target" Then
mails_itm.Delete
End If
Next mails_itm
End Sub
many thanks in advance
Regards,
Premanshu