Attachment delete method

G

Guest

Hi everybody,

I use OL 2003 and I use the following code to save the incoming mail
attachments (based on a rule of the sender name and subject) on a specific
folder in My Documents, delete the attachments and clear the space:

strControl = subsubfolder.Items.Count
Set olMail = subsubfolder.Items(strControl) ' to get the last
mailItem moved in the folder by the rule

For Each atm In olMail.Attachments
atm.SaveAsFile "C:\Documents and Settings\..." & atm.FileName
Next

For Each atm In olMail.Attachments
atm.Delete
Next

The problem is that the attachments are not deleted.
I am a newbie with VBA. Can somebody help me please ?

Also, is there any other method which returns the last mailItem received in
a specific folder? How can I use AddItem method in the rule?

Thanks in advance,
Catalin
 
M

Michael Bednarek

I use OL 2003 and I use the following code to save the incoming mail
attachments (based on a rule of the sender name and subject) on a specific
folder in My Documents, delete the attachments and clear the space:

strControl = subsubfolder.Items.Count
Set olMail = subsubfolder.Items(strControl) ' to get the last
mailItem moved in the folder by the rule

For Each atm In olMail.Attachments
atm.SaveAsFile "C:\Documents and Settings\..." & atm.FileName
Next

For Each atm In olMail.Attachments
atm.Delete
Next

The problem is that the attachments are not deleted.
I am a newbie with VBA. Can somebody help me please ?
[snip]

From memory, try adding this:
olMail.Save
 
G

Guest

Thank you very much Michael and Ken. You have been very helpful.

Well, can you also tell me how I can refer to the last mailItem received in
a folder using AddItem ? is there any way to do that?

Thanks,
Catalin

Michael Bednarek said:
I use OL 2003 and I use the following code to save the incoming mail
attachments (based on a rule of the sender name and subject) on a specific
folder in My Documents, delete the attachments and clear the space:

strControl = subsubfolder.Items.Count
Set olMail = subsubfolder.Items(strControl) ' to get the last
mailItem moved in the folder by the rule

For Each atm In olMail.Attachments
atm.SaveAsFile "C:\Documents and Settings\..." & atm.FileName
Next

For Each atm In olMail.Attachments
atm.Delete
Next

The problem is that the attachments are not deleted.
I am a newbie with VBA. Can somebody help me please ?
[snip]

From memory, try adding this:
olMail.Save
 
K

Ken Slovak - [MVP - Outlook]

You'd have to sort the Items collection for that folder by date, then you
could easily pick out the first or last items in the folder.
 

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

Similar Threads


Top