Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook Remove method

Status
Not open for further replies.

danvlas

Programmer
Jul 30, 2002
2,446
RO
What I want to do is to remove automatically the attachments from all the messages stored in Sent Items. For this purpose I wrote the following code and, when run step by step, it reports that the attachments have been removed. However, they remain in place and I can't figure what is wrong... Anyone any idea?

Sub RemoveAttachments()
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set MyFolder = myNameSpace.Folders("Personal Folders")
Set SentFld = MyFolder.Folders("Sent Items")

For myCounter = 1 To SentFld.Items.Count
Set myitem = SentFld.Items(myCounter)
Set myattachments = myitem.Attachments
If myattachments.Count > 0 Then
While myattachments.Count > 0
Debug.Print "removing 1 attachment from " & myitem
myattachments.Remove 1
myitem.Save
Wend
Debug.Print "remaining attachments: " & myitem.Attachments.Count
End If
Next
End Sub

The parts in red indicate how I checked whether the attachments were removed...

What is wrong with the code?

Thanks in advance,

Dan
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top