J
joannele71
Hi
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.
Or if you have a better way to do this, please let me know.
Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myItem = Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
myItem.Display
Set myOlApp = CreateObject("Outlook.Application")
Set myInspector = myOlApp.ActiveInspector
If Not TypeName(myInspector) = "Nothing" Then
If TypeName(myInspector.CurrentItem) = "MailItem" Then
Set myItem = myInspector.CurrentItem
Set myAttachments = myItem.Attachments
myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If
End Sub
I am trying to find a macro to save the attachment automatically every time
I receive emails from the same person. The following is my macro. I have
set up the rule to run the script (macro) when the condition is met. I
receive three different emails that meet the condition and they are all
coming at about the same time. However, the script doesn't work at all and I
got the error message "rule operation failed". Sometimes, it works for one
email and sometimes, it doesn't work at all. Please help!! Thanks in
advance.
Or if you have a better way to do this, please let me know.
Sub SaveAttachment(Item As Outlook.MailItem)
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Set myItem = Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
myItem.Display
Set myOlApp = CreateObject("Outlook.Application")
Set myInspector = myOlApp.ActiveInspector
If Not TypeName(myInspector) = "Nothing" Then
If TypeName(myInspector.CurrentItem) = "MailItem" Then
Set myItem = myInspector.CurrentItem
Set myAttachments = myItem.Attachments
myAttachments.Item(1).SaveAsFile "c:\" & _
myAttachments.Item(1).DisplayName
myItem.Close olDiscard
End If
Else
' MsgBox "The item is of the wrong type."
myItem.Close olDiscard
End If
End Sub