|
收到新邮件后,附件自动保存到c盘下,文件名为:发件人+原始文件名。
如果想保存到别的地方,自己改改。
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim mai As Object
Dim intInitial As Integer
Dim intFinal As Integer
Dim strEntryId As String
Dim intLength As Integer
Dim mlItem As Outlook.mailItem
Dim replyItem As Outlook.mailItem
intInitial = 1
intLength = Len(EntryIDCollection)
intFinal = InStr(intInitial, EntryIDCollection, ",")
Do While intFinal <> 0
strEntryId = Strings.Mid(EntryIDCollection, intInitial, (intFinal - intInitial))
Set mai = Application.session.GetItemFromID(strEntryId)
intInitial = intFinal + 1
intFinal = InStr(intInitial, EntryIDCollection, ",")
Loop
strEntryId = Strings.Mid(EntryIDCollection, intInitial, (intLength - intInitial) + 1)
Set mai = Application.session.GetItemFromID(strEntryId)
Dim myAttachments As Outlook.Attachments
Set myAttachments = mai.Attachments
Dim filename As String
filename = mai.SenderName & " " & myAttachments.Item(1).DisplayName
If TypeName(mai) = "MailItem" Then
myAttachments.Item(1).SaveAsFile "C:\" & _
filename
End If
End Sub
|
|