2

I am trying to save attachments sent to a shared inbox to disk.

Public Sub CSD_SaveAttachmentsToDisk(MItem As Outlook.MailItem)

    Dim oAttachment As Outlook.Attachment
    Dim sSaveFolder As String
    sSaveFolder = "C:\Users\user\Documents\"
    For Each oAttachment In MItem.Attachments
        Debug.Print ("saving...")
        oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
    Next oAttachment
End Sub

I'm using Outlook 2016, and have a rule which calls this script on all messages.

The messages aren't saved.

Rule settings

Community
  • 1
  • 1
pawlactb
  • 109
  • 1
  • 9
  • Does it print out the `saving...` debug line? – Marcucciboy2 Sep 26 '18 at 14:16
  • It does not. Which I find odd because the rule running this script is applied to every message in the inbox. – pawlactb Sep 26 '18 at 14:19
  • Maybe have it msgbox `MItem.Attachments.Count` before the loop to make sure that you're grabbing mails with attachements – Marcucciboy2 Sep 26 '18 at 14:22
  • I added the msgbox, and nothing is appearing. – pawlactb Sep 26 '18 at 14:25
  • Are you checking that the function passing this one mail items checks that the messages *have* attachments first? You could check in this one that the 'right' messages are being passed to it by printing the `MItem.Subject` or something like that – Marcucciboy2 Sep 26 '18 at 14:27
  • So I added a msgbox with the message subject to the function, and that isn't appearing either. Is there a reason this rule wouldn't be calling the script? – pawlactb Sep 26 '18 at 14:32
  • I'm using rules to run a script. Is there a better way to do that? – pawlactb Sep 26 '18 at 14:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/180813/discussion-between-tyler-p-and-marcucciboy2). – pawlactb Sep 26 '18 at 14:52
  • This post describes attachments not being recognized when a rule runs https://stackoverflow.com/questions/49483298/why-does-attachments-count-return-0-on-incoming-mail-with-attachments – niton Sep 26 '18 at 20:08
  • This post describes slowing processing so missing information becomes available https://stackoverflow.com/questions/45661919/outlook-run-script-rule-not-triggering-vba-script-for-incoming-messages – niton Sep 26 '18 at 20:10
  • As a workaround put the move in the code. – niton Sep 16 '21 at 22:56

0 Answers0