Outlook VBA 2013:自动保存附件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18234934/
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 VBA 2013 : Automating Saving of Attachments
提问by CatParky
I'm using the following code to save email photo's to a specific folder :
我正在使用以下代码将电子邮件照片保存到特定文件夹:
Private Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "C:\Temp\"
For Each objAtt In itm.Attachments
If objAtt.FileName <> "image001.gif" Then
objAtt.SaveAsFile saveFolder & "\" & itm.Subject & ".JPG"
End If
Set objAtt = Nothing
Next
End Sub
However I can't get it to actually work. I've tried saving it in ThisOutlookSession and as a module attached to a rule but nothing is being saved.
但是我无法让它实际工作。我试过将它保存在 ThisOutlookSession 中,并将其作为附加到规则的模块,但没有保存任何内容。
I'm also looking to create another script to save the comments of the email to a text file where the specific text would be written in [COMMENT] tags in the body. Is this possible ?
我还希望创建另一个脚本,以将电子邮件的评论保存到文本文件中,其中特定文本将写入正文的 [COMMENT] 标签中。这可能吗 ?
回答by niton
There is an extra "\" in the path.
路径中有一个额外的“\”。
Try objAtt.SaveAsFile saveFolder & itm.Subject & ".JPG"
尝试 objAtt.SaveAsFile saveFolder & itm.Subject & ".JPG"
or saveFolder = "C:\Temp"
或 saveFolder = "C:\Temp"
回答by CatParky
This is the code I got to work :
这是我开始工作的代码:
Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim dateFormat
dateFormat = Format(Now, "yyyy-mm-dd")
'Message subject should be the meter serial number i.e.K11TB00864
Dim subject
subject = Trim(itm.subject)
Dim saveFolder As String
saveFolder = "C:\Temp\Photo"
For Each objAtt In itm.Attachments
If objAtt.FileName <> "image001.gif" Then
objAtt.SaveAsFile saveFolder & "\" & itm.subject & " " & dateFormat & ".jpg"
End If
Set objAtt = Nothing
Next
End Sub