
April 22nd, 2004, 10:20 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Outlook Macro help needed
Can someone take a look at this? The problem I'm having is, sometimes it misses the files in some messages. I think it may be just running too fast, maybe?
This goes in "ThisOutlookSession"
Code:
Private Sub Application_NewMail()
On Error GoTo GetAttachments_err
Dim Inbox As MAPIFolder
Dim email As MailItem
Dim Atmt As Attachment
Dim i As Integer, Count As Integer
Const FileName = "D:\Program Files\ATS M5000\To WordScript\"
Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
i = 0
If Inbox.Items.Count = 0 Then Exit Sub
'cycle through emails
For Each email In Inbox.Items
If email.Subject = "Dictation" Then
If email.Attachments.Count > 0 Then
For Count = email.Attachments.Count To 1 Step -1
Set Atmt = email.Attachments.Item(Count)
If LCase(Right(Atmt.FileName, 3)) = "wav" Or _
LCase(Right(Atmt.FileName, 3)) = "xml" Then
Atmt.SaveAsFile (FileName & Atmt.FileName)
Atmt.Delete
i = i + 1
End If
Next Count
email.Save
End If
End If
Next email
If i > 0 Then
MsgBox " " & i & " attached files were found." _
& vbCrLf & "They have been copied to your work folder." _
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
End If
GetAttachments_exit:
Set Atmt = Nothing
Set email = Nothing
Exit Sub
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit
End Sub
|