Remove mail macro

Remove mail macro

Post by Kell » Thu, 22 Jan 2004 05:52:48

Hi group, I am using office Exchange 2000

The following is some code I managed to find and
manipulate so that a specific file could be stripped form
an incoming email and placed in a specific folder.

I would like to add three things to this code.

Any suggestions would be greatly appreciated.

1. I would like to fire this macro AFTER the rule I set up
delivers a new message to the "expense claims" folder.

2. I would like suggestions on an error handler. (As there
should never be multiple attachments that situation
probably won't be an issue but there is always a chance
the code will error and I would like to be prepared)

3. The way the code is now if someone emails in an
attachment with the same name as a previous one it just
gets saved over the old one with no message asking " are
you sure you want to save over the old one?" so this would
be a nice feature but I am not sure of the code needed.

Here is what I have so far, thanks for any input!

Sub Remove_Expense_Claims()

Set MAPI = Outlook.GetNamespace("MAPI")
Set TopFolder = MAPI.Folders.Item("Mailbox - My Name")
Set ClaimsFolder = TopFolder.Folders.Item("expense claims")

intCount = ClaimsFolder.Items.Count
For i = intCount To 1 Step -1
Set myItem = ClaimsFolder.Items(i)
For Each Att In myItem.Attachments
Att.SaveAsFile "C:\Documents and Settings\krk\My
Documents\Employee Expense Claims\" & Att.FileName

End Sub

Remove mail macro

Post by Ken Slovak » Thu, 22 Jan 2004 22:54:21

You cannot control when something fires relative to when a rule fires
automatically. If you are manually executing the macro just wait a
while to run it so the rule can fire.

An error handler can be as simple as On Error Resume Next or can use
On Error GoTo <label> where <label> is your error handler and can test
as many different error conditions, log them and/or display messages
about the errors as you want.

You could use Windows Scripting to test whether a file already exists
with the same name:

Dim oFSO As Scripting.FileSystemObject
Dim blnOKName As Boolean
Dim lngAdder As Long

Set oFSO = CreateObject("Scripting.FileSystemObject")

'within the loop just after For Each
blnOKName = False
lngAdder = 1
strFile = "C:\Documents and Settings\krk\" _
& "My Documents\Employee Expense Claims\" _
& Att.FileName

If oFSO.FileExists(strFile) Then
strFile = strFile & CStr(lngAdder)
lngAdder = lngAdder + 1
blnOKName = True
End If
Loop Until blnOKName

Set oFSO = Nothing
Att.SaveAsFile strFile