我有一个简短的Outlook VBA宏,可以将附件从特定的电子邮件下载到特定的文件夹。
我的设置如下:
Apply this rule after the message arrives
From ******@***.com
And on this computer only
Move it to the pricing folder
And run Project1.saveAttachtoDrive对于outlook规则。
宏设置:图片上的默认设置,宏设置上的“启用所有宏”。
代码:
Public Sub saveAttachtoDrive(itm As Outlook.MailItem)
'Created by Selkie in order to automatically download attachments
Dim objAtt As Outlook.Attachment
'Shortening things
Dim dt As Date
'The date
Dim saveFolder As String
'We need to save the file somewhere
dt = Format(Date, "MMDDYY")
'Gotta get the date, and need it in a useable format
saveFolder = "L:\*******\Testing Folder\"
'Save location - change as needed
For Each objAtt In itm.Attachments
'For every attachment we get
objAtt.SaveAsFile saveFolder & dt & objAtt.DisplayName
'Save it
Set objAtt = Nothing
Next
End Sub现在,当我运行一些非常类似的东西时,但作为文件夹抓取而不是收到电子邮件时的触发器,我确实设法下载了给定文件中的附件。
我是不是做错了什么?是否需要启用某些Outlook设置?或者我是不是完全抄袭了代码?(看起来与我在3-4个不同位置看到的东西非常相似,只是位置、注释和添加日期是独一无二的。)
发布于 2017-03-15 03:13:51
您的问题是您的文件名并不是您认为的那样,因为您已经将dt声明为Date,因此Format输出的字符串被强制返回到日期中,而不是保留为字符串。
Sub Tester()
Dim dt As Date '<<
dt = Format(Date, "MMDDYY")
Debug.Print dt '>> 1/5/1986 :same as CDate("031417")
Dim dt2 As String '<< Note
dt2 = Format(Date, "MMDDYY")
Debug.Print dt2 '>> 031417
End Subhttps://stackoverflow.com/questions/42793830
复制相似问题