BookmarkSubscribeRSS Feed
Abelp9
Quartz | Level 8

Good morning, I'm trying to automate a process and it all starts when a robot sends me 8 emails with a csv file attached. I have searched the internet and I have found code in VBA to create a rule in Outlook and be able to download the csv automatically when the mail arrives.

 

The VBA code I used to do this is as follows:

Public Sub saveAttachtoDisk2(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "J:\xx\xx\xxxx\xxx\xx\xxx\2. Correcciones\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & objAtt.FileName
Set objAtt = Nothing
Next
End Sub

What I want is that I save the files in a specific path and that I only download the csv, right now it downloads the csv and 2 photos (.png) that it takes from the email signature. I don't have much idea about VBA, does anyone know how I can limit the code so that it only downloads csv files?

 

And another question I have is that when I do tests and send many emails in a row, it gives me the following error "the error -2147024894 has occurred at runtime, the attachments cannot be saved" and I don't know what could be the cause , since when they send me an email, 30 seconds go by and they send me another, it doesn't give me an error, but if they send them to me en masse, yes.

Does anyone know why this could be happening?

1 REPLY 1
SASJedi
SAS Super FREQ

In your FOR loop, use the Attachment.FileName property to get the filename of each attachment and only save CSV files. I haven't done any VBA in years, but something like this perhaps?

 

if right(Attachment.FileName,3)="csv" then objAtt.SaveAsFile saveFolder & objAtt.FileName

 

Check out my Jedi SAS Tricks for SAS Users

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 552 views
  • 0 likes
  • 2 in conversation