Anda di halaman 1dari 1

Private WithEvents Items As Outlook.

Items Private Dim Dim Set Set Set End Sub Sub Application_Startup() olApp As Outlook.Application objNS As Outlook.NameSpace olApp = Outlook.Application objNS = olApp.GetNamespace("MAPI") Items = objNS.GetDefaultFolder(olFolderInbox).Items

Private Sub Items_ItemAdd(ByVal item As Object) On Error GoTo ErrorHandler 'Only act if it's a MailItem Dim Msg As Outlook.MailItem If TypeName(item) = "MailItem" Then Set Msg = item 'Change variables to match need. Comment or delete any part unnecessary. If (Msg.SenderName = "Name Of Person") And _ (Msg.Subject = "Subject to Find") And _ (Msg.Attachments.Count >= 1) Then 'Set folder to save in. Dim olDestFldr As Outlook.MAPIFolder Dim myAttachments As Outlook.Attachments Dim Att As String 'location to save in. Can be root drive or mapped network drive. Const attPath As String = "C:\" ' save attachment Set myAttachments = item.Attachments Att = myAttachments.item(1).DisplayName myAttachments.item(1).SaveAsFile attPath & Att ' mark as read Msg.UnRead = False End If End If ProgramExit: Exit Sub ErrorHandler: MsgBox Err.Number & " - " & Err.Description Resume ProgramExit End Sub

Anda mungkin juga menyukai