I receive e-mails, from two vendors, that have two types of attachments, with extension of xml and pdf.
XML can contain data of three types, which is reflected in the name of the XML file.
The types of XML let's say can be: "IE529", "IE599", "ZC299".
XMLs from Vendor "A" are named like this: (...)ZC299(...).xml
XMLs from Vendor "B" are named like this: ZC299 (...).xml --> there is space here.
I want to save only XML files, depending on the type, to one of three folders, however my script works only for Vendor B.
I assume my problem is, that my script searches for separate name "ZC299", but doesn't recognize it when it is hidden in the middle of filename.
Public Sub Komunikaty(MItem As Outlook.MailItem)
Dim Zalacznik As Outlook.Attachment
Dim KatalogIE529 As String
Dim KatalogIE599 As String
Dim KatalogZC299 As String
KatalogIE529 = "C:(...)"
KatalogIE599 = "C:(...)"
KatalogZC299 = "C:(...)"
For Each Zalacznik In MItem.Attachments
If InStr(1, Zalacznik.DisplayName, "IE529", vbTextCompare) And InStr(1, Zalacznik.DisplayName, ".xml", vbTextCompare) Then
Zalacznik.SaveAsFile KatalogIE529 & "\" & Zalacznik.DisplayName
ElseIf InStr(1, Zalacznik.DisplayName, "IE599", vbTextCompare) And InStr(1, Zalacznik.DisplayName, ".xml", vbTextCompare) Then
Zalacznik.SaveAsFile KatalogIE599 & "\" & Zalacznik.DisplayName
ElseIf InStr(1, Zalacznik.DisplayName, "ZC299", vbTextCompare) And InStr(1, Zalacznik.DisplayName, ".xml", vbTextCompare) Then
Zalacznik.SaveAsFile KatalogZC299 & "\" & Zalacznik.DisplayName
End If
Next
End Sub