Rule using VBA for outlook to enrgegsitrer an attachment in a directory on my disk

Jean-Paul DOUET 1 Reputation point

This script worked once but no longer works and no fault return
Public Sub SaveAttachmentsToDisk(MyMail As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment Const sSaveFolder = "C:\Users\outlookJP\"
For Each oAttachment In MyMail.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName

{count} votes

2 answers

Sort by: Most helpful
  1. Oskar Shon 866 Reputation points MVP

    I can recommend you my COM Addin for Outlook Desktop to save attachments as rule or as right click to select some

    or export with delete it from mail (inserting path into mail) saved your account space


    0 comments No comments

  2. Eugene Astafiev 806 Reputation points

    First of all, you when saving anything to the disk you need to make sure that no forbidden symbols are used in the file path. In the code sample the path is built based on the DisplayName property value:

       oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName  

    Make sure the DisplayName property value contains a valid file name.

    Also you may try using the FileName property of the Attachment class which returns a string representing the file name of the attachment.

    Finally, if the code still doesn't work you may try to run it under the debugger attached and check where it fails.

    0 comments No comments