【问题标题】:Outlook attachments not downloading automatically or properly - using a scriptOutlook 附件未自动或正确下载 - 使用脚本
【发布时间】:2020-06-28 15:06:42
【问题描述】:

我有一个简短的 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

对于前景规则。

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

代码:

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 个不同位置看到的东西非常相似,只是位置、cmets 和添加的日期都是独一无二的”

【问题讨论】:

  • 运行时实际发生了什么?你没有描述出了什么问题,除了你的帖子标题。
  • 绝对没有。电子邮件进来了,但附件不会保存。所以我想这是出乎意料的行为

标签: vba outlook


【解决方案1】:

您的问题是您的文件名不是您认为的那样,因为您已将 dt 声明为日期,因此 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 Sub

【讨论】:

  • 谢谢!自我注意:从工作宏中更好地复制粘贴 >_>
猜你喜欢
  • 1970-01-01
  • 2017-02-01
  • 1970-01-01
  • 2012-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-20
  • 2023-03-15
相关资源
最近更新 更多