我想创建一个运行以下脚本的规则:
Public Sub SaveToDisk(itm As Outlook.MailItem) Dim objAtt As Outlook.Attachment Dim saveFolder As String Dim dateFormat dateFormat = Format(Now, "yyyy-mm-dd") saveFolder = "c:\temp\" objAtt.SaveAsFile saveFolder & "\" & dateFormat & ".xls" Set objAtt = Nothing End Sub这应该保存到c:\ temp文件夹的附件,但它不起作用,因为objAtt值什么都没有。 由于某些原因,该行:
Dim objAtt As Outlook.Attachment不会将附件分配给obAtt变量,原因我无法弄清楚。 这里的附件是.csv文件。
我在Windows 10上使用Outlook 2016。我很乐意就此为何发生任何建议。
I would like to create a rule which run the following script:
Public Sub SaveToDisk(itm As Outlook.MailItem) Dim objAtt As Outlook.Attachment Dim saveFolder As String Dim dateFormat dateFormat = Format(Now, "yyyy-mm-dd") saveFolder = "c:\temp\" objAtt.SaveAsFile saveFolder & "\" & dateFormat & ".xls" Set objAtt = Nothing End SubThis should save the attachment to the c:\temp folder but it does not work because objAtt value is nothing. For some reasons the line:
Dim objAtt As Outlook.Attachmentdoes not assign the attachment to the obAtt variable for a reason I can't figure it out. Here the attachment is a .csv file.
I am using outlook 2016 on windows 10. I would be glad to get any advice on why this is happening.
最满意答案
你必须设置对象,因为你只是创建它,而不是填充它。
所以它不知道它应该与MailItem有任何关系。
此外,还有一系列的Attachement可以通过,请参阅:
Public Sub SaveToDisk(ItM As Outlook.MailItem) Dim oAttS As Outlook.Attachments Dim objAtt As Outlook.Attachment Dim saveFolder As String Dim dateFormat dateFormat = Format(Now, "yyyy-mm-dd") saveFolder = "c:\temp\" Set oAttS = ItM.Attachments For Each objAtt In oAttS objAtt.SaveAsFile saveFolder & "\" & dateFormat & "_" & objAtt.FileName Next objAtt Set oAttS = Nothing Set objAtt = Nothing End SubYou have to set the object, because you where just creating it, not filling it.
So it had no clue it was supposed to be in any relation with the MailItem.
Further more, there is a collection of Attachement to go through, see :
Public Sub SaveToDisk(ItM As Outlook.MailItem) Dim oAttS As Outlook.Attachments Dim objAtt As Outlook.Attachment Dim saveFolder As String Dim dateFormat dateFormat = Format(Now, "yyyy-mm-dd") saveFolder = "c:\temp\" Set oAttS = ItM.Attachments For Each objAtt In oAttS objAtt.SaveAsFile saveFolder & "\" & dateFormat & "_" & objAtt.FileName Next objAtt Set oAttS = Nothing Set objAtt = Nothing End Sub更多推荐
发布评论