0
votes

Background: I receive several daily Infection Control Reports in pdf format from our electronic medical records system via Outlook email attachments.

Request: Given the large number of reports, I am trying to find a way to autosave the attachments using an outlook rule. Currently, the code I use works only to save the attachment with its respective received date. However, these medical reports largely reflect the previous day's data. Therefore, I was wondering, How would I format this code so that it will take the email attachment's received date less (minus) 1 day, and autosave it in a specified location?

Here is what I have so far:

Sub Save_DailyFluReport(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim dateFormat As String
Dim saveFolder As String

dateFormat = Format(itm.ReceivedTime, "dd-mmmm-yyyy")
saveFolder = "Z:\Infection Control\IP Daily Surveillance Reports"
    For Each objAtt In itm.Attachments
          objAtt.SaveAsFile saveFolder & "\" & dateFormat & " - " & objAtt.DisplayName
        Set objAtt = Nothing
     Next
End Sub
1

1 Answers

0
votes

I figured it out! Hope this solution can help someone else in the future.

Sub Save_DailyFluReport(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim dateFormat As String
Dim saveFolder As String

dateFormat = Format(DateSerial(Year(itm.ReceivedTime), Month(itm.ReceivedTime), Day(itm.ReceivedTime) - 1), "dd-mmmm-yyyy")
saveFolder = "Z:\Infection Control\IP Daily Surveillance Reports"
    For Each objAtt In itm.Attachments
          objAtt.SaveAsFile saveFolder & "\" & dateFormat & " - Daily Flu Report.pdf"
        Set objAtt = Nothing

     Next
End Sub