首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Outlook附件未自动或正确下载-使用脚本

Outlook附件未自动或正确下载-使用脚本
EN

Stack Overflow用户
提问于 2017-03-15 02:29:54
回答 1查看 501关注 0票数 2

我有一个简短的Outlook VBA宏,可以将附件从特定的电子邮件下载到特定的文件夹。

我的设置如下:

代码语言:javascript
复制
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规则。

宏设置:图片上的默认设置,宏设置上的“启用所有宏”。

代码:

代码语言:javascript
复制
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个不同位置看到的东西非常相似,只是位置、注释和添加日期是独一无二的。)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-15 03:13:51

您的问题是您的文件名并不是您认为的那样,因为您已经将dt声明为Date,因此Format输出的字符串被强制返回到日期中,而不是保留为字符串。

代码语言:javascript
复制
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 Sub
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42793830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档