Select Mail attachment that's Excel or any extension I am looking for

I was following the RPA Developer foundation course in Academy. The first exercise has you create a process in Studio that reads an Email with subject New Task, Downloads the Excel Attachment and read range from the Excel workbook into a datatable.

My Outlook email has my signature with my company logo and pngs for Linked In and a bunch of other logos. So when I followed the exercise and first tried to read range using the following:
MailMessages[0].Attachments[0].Name, I got an error saying PNG is not supported, then realized it could be the logo in my signature. So I had a MessageBox activity to read out the names and found that the fifth attachment in the Attachments collection was the Excel one. Is there a way in code to use linq or if condition or a for each loop to get the attachment whose name has .xslx in its name and read range from that attachment?

You can use an assign to get the CType of the attachment and then put that in an if statement before you download the attachment

in assign AttachmentName = CType(item.Attachments.FirstOrDefault, attachment).Name

where Item is what you have in your for each loop…then do an if statement

Hope that helps

Chris

Linq:
firstAttachXls = MailMessages[0].Attachments.FirstOrDefault(Function(a) a.Name.ToLower.Contains(“.xls”))

This return attachment or nothing value.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.