You cannot change standalone VBA by simply adding (mail As Outlook.MailItem).
Public Sub SaveAttachments2(mail As Outlook.mailItem)
Dim Atmt As attachment
Dim FileName As String
Dim f As String
f = Trim(mail.Subject) ' Removes spaces at ends. This is a big problem.
On Error Resume Next
MkDir ("Z:\OPERATIO\AS400_Report\" & f) ' Creates a folder if it does not exist
On Error GoTo GetAttachments_err
For Each Atmt In mail.Attachments
FileName = "Z:\OPERATIO\AS400_Reports\" & f & "\" & Atmt.FileName
Atmt.SaveAsFile FileName
' Fails on subjects with illegal characters.
' For example when RE: and FW: in the subject the folder cannot be created.
Next Atmt
GetAttachments_exit:
Exit Sub
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: SaveAttachments2" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit
End Sub
See here if illegal characters cause problems creating folders. Save mail with subject as filename