Reputation: 11
An Outlook rule executes code every time an e-mail from a certain sender is received. It would automatically extract the PDF attachment from e-mails and put them into a specified folder.
We've been using it for a good 9 months.
From around 10/22 it crashes on the line For Each oAttachment In MItem.Attachments
with Error 424 Object Required.
in the DAKSave portion.
I have tried changing the folder to a local folder, same error. This error also occurs on different computers when I try using the code (including a computer which WAS able to use that specific code previously).
I have enabled EnableUnsafeClientMailRules in regedit.
Why isn't it working? Why was it working until now?
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "S:\Fax\FAX AUTODUMP\"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
Sub DAKSave()
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "S:\Fax\FAX AUTODUMP\"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
I'm open to suggestions that would accomplish the same automated task.
Upvotes: 1
Views: 976
Reputation: 66286
MItem
is not passed as a parameter to the DAKSave
sub. MItem
is undefined in DAKSave
. It is only available in the SaveAttachmentsToDisk
sub.
Upvotes: 0
Reputation: 12497
Your missing mail Item object, so try to work with ActiveExplorer.Selection.Item(1)
Option Explicit
Sub DAKSave()
Dim sSaveFolder As String
sSaveFolder = "S:\Fax\FAX AUTODUMP\"
Dim MItem As Outlook.MailItem
Set MItem = ActiveExplorer.Selection.Item(1)
Dim oAttachment As Outlook.attachment
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
Upvotes: 1