Hi everyone
First time poster here. I am trying to edit this script to automatically download attachment(s) from certain emails (based on rules) and rename the attachment to what is in the subject line. The subject line typically says:
"Ticket # 1111111111 Order # 999999999" and I would like to return to only the "1111111111". The file type is usually .pdf if that matters.
By looking around, I only have the following code that will download the attachment and save it as it is.
This is what I have so far but it is not working obviously:
First time poster here. I am trying to edit this script to automatically download attachment(s) from certain emails (based on rules) and rename the attachment to what is in the subject line. The subject line typically says:
"Ticket # 1111111111 Order # 999999999" and I would like to return to only the "1111111111". The file type is usually .pdf if that matters.
By looking around, I only have the following code that will download the attachment and save it as it is.
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "path here"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
Set objAtt = Nothing
Next
End Sub
This is what I have so far but it is not working obviously:
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim Subject As String
Dim Ticket As String
saveFolder = "path here"
For Each objAtt In itm.Attachments
Subject = itm.Subject
If InStr(1, Subject, "#") > 0 Then
'Trim beginning of subject
Subject = Mid(Subject, InStr(Subject, "#") + 1)
'Trim ending of subject
If InStr(Subject, " ") > 0 Then
Ticket = Left(Subject, InStr(Subject, " Order") - 1)
End If
End If
objAtt.SaveAsFile saveFolder & "\" & Invoice
Set objAtt = Nothing
Next
End Sub