Before this gets flagged as similar it is not quite the same as other questions that have been asked.
I have a script that I found that currently saves attachments but I also need it to rename those attachments to the same name. For a little background I am creating a system that updates inventory on one of my websites. To do this I get a report(CSV) from our ERP with all my item numbers and inventory counts. They are emailed to me but the attached CSV always has a name that ends in a different number. I need the file to have the same name every time because the script I have saves that CSV to a folder and I have a FTP program that auto FTPs that CSV to my web server. From here I have a PHP script on a cron job that runs through the CSV and updates the quantity on my products.
Believe me, if my ERP had an API this would be so much easier but no luck on that.
Anyhow, my issue lies in the naming of the attachment. The script below saves it but I need it to also strip the numbers from the name or just name it to 'CPNINVTRUM'.
Public Sub saveAttachtoDisk(itm As Outlook.MailItem) Dim objAtt As Outlook.Attachment Dim saveFolder As String saveFolder = "C:\PATH" For Each objAtt In itm.Attachments objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName Set objAtt = Nothing Next End Sub
If someone could help me add to this script the function to rename the file that would be great.
EDIT: The attachment is always in this form: CPNINVTRUM###.csv. The ### signifies the the 3 digit random number that is generated by the ERP.