deleting Outlook attachments
My VB code for saving attachments to a file and then deleting them from the email saved the file just fine and SEEMED to do the delete as well (I got no error, or any message saying the delete didn't work) BUT the attachment did not go away. I moved the code into VBA inside Outlook, thinking that there was a security setting that prevented external code from doing a delete. My security setting is "LOW" (as low as it can be set). The code had exactly the same effect inside Outlook as outside -- the attachment saves as a file just fine but the delete method, despite giving no indication that it isn't doing anything, doesn't do any thing.
Help !
Thanks,
Paul
[708 byte] By [
phinds] at [2007-11-20 11:32:47]

# 1 Re: deleting Outlook attachments
How can we help if you don't help yourself?
We can't see your code, so if you want us to help, post it.
' Use Code Tags
# 2 Re: deleting Outlook attachments
good point, although I suspect that the problem is somehow with the security setting, not the code.
Here's the code
Private Sub sub2()
Dim oApp As Outlook.Application
Dim oNameSpace As NameSpace
Dim oFolder As MAPIFolder
Dim oMailItem As MailItem
Dim sMessage As String
Dim n As Integer
Set oApp = New Outlook.Application
Set oNameSpace = oApp.GetNamespace("MAPI")
Set oFolder = oNameSpace.PickFolder
n = 0
For Each oMailItem In oFolder.Items
With oMailItem
If oMailItem.Attachments.Count > 0 Then
oMailItem.Attachments.Item(1).SaveAsFile "c:\temp\temp\" & Format(CStr(n), "00#") & _
oMailItem.Attachments.Item(1).FileName
If InStr(1, oMailItem.Attachments.Item(1).FileName, "2006 phinds") <> 0 Then
oMailItem.Attachments.Item(1).Delete
n = n + 1
End If
DoEvents
End If
End With
Next oMailItem
MsgBox "n = " & n
Set oMailItem = Nothing
Set oFolder = Nothing
Set oNameSpace = Nothing
Set oApp = Nothing
End Sub
phinds at 2007-11-9 19:34:06 >

# 3 Re: deleting Outlook attachments
That could be. Does a macro work from within outlook?
# 4 Re: deleting Outlook attachments
Don't quite see how I could test that since capturing the macro means deleting an attachment during the macro capture but then re-running the macro would be pointless since the attachment would already be gone.
phinds at 2007-11-9 19:36:04 >

# 5 Re: deleting Outlook attachments
edit the code in the VBA Editor. Record the macro to do one file, and then edit to do another.
I think it's permissions that you'd need a certificate to get around
# 6 Re: deleting Outlook attachments
good idea on the macro thing ... I'll try that tomorrow.
Any idea how to change permissions or get a certificate? I have the outlook security permissions set as low as they'll go, so what am I missing?
Thanks,
Paul
phinds at 2007-11-9 19:38:08 >

# 7 Re: deleting Outlook attachments
This looks painless:
http://www.msexchange.org/tutorials/Creating-Certificate-OWA2003-SelfSSL.html
# 8 Re: deleting Outlook attachments
Ah, I appreciate the suggestion, but this seems to apply only to IIS installations which I do not have, AND the documentation says only use this facility, and I quote, " When you have to create a security-enhanced private channel between your server and a limited, known group of users" -- seems to imply that it will screw up my email to other users, which I cannot afford.
phinds at 2007-11-9 19:40:15 >

# 9 Re: deleting Outlook attachments
>> Does a macro work from within outlook?
OK, I tried the code as a macro but it acts exactly the same -- no surprize there since you can't RECORD macros in outlook so this is not a macro created by outlook, it's just a new name for the same code pasted into a macro name.
Still, this all does seem to imply that there's a security problem, not a code problem.
Any suggestions?
Thanks,
Paul
phinds at 2007-11-9 19:41:08 >
