I am not very savvy with the coding. I found one and lightly modified it to save attachments using the subject name for me. I need assistance on getting it to save the attachments as only part of the subject name.
Subject name, "[EXTERNAL] APLORD:214 File for admission 0220X0119AO002198"
Needed attachment just saved as, "0220X0119AO002198"
If you are able to help, i would GREATLY appreciate it as i have to sort through hundreds of these emails daily.
Public Sub saveAttachtoDisk()
Dim itm As Outlook.MailItem
Dim currentExplorer As Explorer
Dim Selection As Selection
Dim strSubject As String, strExt As String
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim enviro As String
enviro = CStr(Environ("USERPROFILE"))
saveFolder = enviro & "\Documents\Attachments"
Set currentExplorer = Application.ActiveExplorer
Set Selection = currentExplorer.Selection
For Each itm In Selection
For Each objAtt In itm.Attachments
' get the last 4 characters for the file extension
strExt = Right(objAtt.DisplayName, 4)
' clean the subject
strSubject = itm.Subject
ReplaceCharsForFileName strSubject, "-"
' put the name and extension together
file = saveFolder & strSubject & strExt
objAtt.SaveAsFile file
Next
Next
Set objAtt = Nothing
End Sub
Private Sub ReplaceCharsForFileName(sName As String, _
sChr As String _
)
sName = Replace(sName, "'", sChr)
sName = Replace(sName, "*", sChr)
sName = Replace(sName, "/", sChr)
sName = Replace(sName, "", sChr)
sName = Replace(sName, ":", sChr)
sName = Replace(sName, "?", sChr)
sName = Replace(sName, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
End Sub
Subject name, "[EXTERNAL] APLORD:214 File for admission 0220X0119AO002198"
Needed attachment just saved as, "0220X0119AO002198"
If you are able to help, i would GREATLY appreciate it as i have to sort through hundreds of these emails daily.
Public Sub saveAttachtoDisk()
Dim itm As Outlook.MailItem
Dim currentExplorer As Explorer
Dim Selection As Selection
Dim strSubject As String, strExt As String
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim enviro As String
enviro = CStr(Environ("USERPROFILE"))
saveFolder = enviro & "\Documents\Attachments"
Set currentExplorer = Application.ActiveExplorer
Set Selection = currentExplorer.Selection
For Each itm In Selection
For Each objAtt In itm.Attachments
' get the last 4 characters for the file extension
strExt = Right(objAtt.DisplayName, 4)
' clean the subject
strSubject = itm.Subject
ReplaceCharsForFileName strSubject, "-"
' put the name and extension together
file = saveFolder & strSubject & strExt
objAtt.SaveAsFile file
Next
Next
Set objAtt = Nothing
End Sub
Private Sub ReplaceCharsForFileName(sName As String, _
sChr As String _
)
sName = Replace(sName, "'", sChr)
sName = Replace(sName, "*", sChr)
sName = Replace(sName, "/", sChr)
sName = Replace(sName, "", sChr)
sName = Replace(sName, ":", sChr)
sName = Replace(sName, "?", sChr)
sName = Replace(sName, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
End Sub