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] [pipe] [pipe]](/data/assets/smilies/pipe.gif)
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
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] [pipe] [pipe]](/data/assets/smilies/pipe.gif)
Daniel Vlas
Systems Consultant
danvlas@yahoo.com