-
Solved: Removing attachments
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:
[VBA]
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
[/VBA]
I cannot see why it wouldn't work so any pointers would be appreciated.
Thanks
-
Knowledge Base Approver
The King of Overkill!
VBAX Master
Hi Chris,
Welcome to VBAX
If you save the message after removing them, it should keep the attachments gone:
[vba]myOlSel.Item(x).Save[/vba]Matt
-
Awesome that works. I didn't realise you needed to save the email but I'll know now for the future.
-
Knowledge Base Approver
The King of Overkill!
VBAX Master
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules