PDA

View Full Version : Solved: Removing attachments



Chris_cs
05-22-2007, 07:03 AM
Hey guys,

I've written a small sub procedure to remove the attachments from any selected emails but it isn't actually removing them. The code is below:


Sub removeAttachments()
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim myattachments As Outlook.Attachments
Dim MsgTxt As String
Dim x As Integer
'MsgTxt = "You have selected items from: "
Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
For x = 1 To myOlSel.Count
Set myattachments = myOlSel.Item(x).Attachments
While myattachments.Count > 0
myattachments.Remove 1
Wend
'MsgTxt = MsgTxt & myOlSel.Item(x).Body & ";"
Next x
MsgBox "Attachments removed"
End Sub


I cannot see why it wouldn't work so any pointers would be appreciated.

Thanks

mvidas
05-22-2007, 10:07 AM
Hi Chris,

Welcome to VBAX :)

If you save the message after removing them, it should keep the attachments gone:
myOlSel.Item(x).SaveMatt

Chris_cs
05-23-2007, 03:40 AM
Awesome that works. I didn't realise you needed to save the email but I'll know now for the future.

mvidas
05-23-2007, 06:31 AM
Yeah I don't think that really is said anywhere in the help files (though I'm sure it is somewhere), just one of those things you learn along the way :)
As an FYI you can mark this solved by going to Thread Tools, then Mark Thread Solved. I'll do it here for you this time, but for future questions ;)

Let me know if you need any more help
Matt