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

Jean-Paul DOUET 1 Reputation point
2022-11-08T06:23:44.13+00:00

Hello
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
    2022-11-08T18:12:42.247+00:00

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

    or export with delete it from mail (inserting path into mail) saved your account space
    eksportuj-i-usun-zalaczniki

    Regards

    0 comments No comments

  2. Eugene Astafiev 891 Reputation points
    2022-11-15T22:10:40.557+00:00

    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