Outlook rename attachments and save to folder

你离开我真会死。 提交于 2019-12-18 09:25:36

问题


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

The attachment is always in this form: CPNINVTRUM###.csv. The ### signifies the the 3 digit random number that is generated by the ERP.


回答1:


Change the save line to

objAtt.SaveAsFile saveFolder & "\CPNINVTRUM.csv"


来源:https://stackoverflow.com/questions/24244636/outlook-rename-attachments-and-save-to-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!