vba Outlook 重命名附件并保存到文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24244636/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Outlook rename attachments and save to folder
提问by smack-a-bro
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.
对于一些背景知识,我正在创建一个系统来更新我的一个网站上的库存。为此,我从我们的 ERP 中获得了一份报告(CSV),其中包含我所有的项目编号和库存数量。
They are emailed to me but the attached CSV always has a name that ends in a different number.
他们通过电子邮件发送给我,但附加的 CSV 总是有一个以不同数字结尾的名称。
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.
我每次都需要该文件具有相同的名称,因为我拥有的脚本将该 CSV 保存到一个文件夹中,并且我有一个 FTP 程序可以自动将该 CSV FTP 传输到我的 Web 服务器。
From here I have a PHP script on a cron job that runs through the CSV and updates the quantity on my products.
从这里开始,我在 cron 作业上有一个 PHP 脚本,该脚本通过 CSV 运行并更新我的产品数量。
Believe me, if my ERP had an API this would be so much easier but no luck on that.
相信我,如果我的 ERP 有一个 API,这会容易得多,但没有运气。
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'.
无论如何,我的问题在于附件的命名。下面的脚本保存它,但我需要它也从名称中去除数字或将其命名为“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.
附件始终采用以下格式:CPNINVTRUM###.csv。### 表示由 ERP 生成的 3 位随机数。
回答by niton
Change the save line to
将保存行更改为
objAtt.SaveAsFile saveFolder & "\CPNINVTRUM.csv"