You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Outlook VBA实现无附件或附件非PDF的邮件移动至Reply文件夹的方法

调整后的Outlook VBA邮件分拣脚本

以下是调整后的完整代码,实现逻辑为:仅当邮件包含至少1个PDF格式附件时留在收件箱,无附件、或所有附件均非PDF格式的邮件自动移动到「Reply」文件夹:

Sub MoveMail(Item As Outlook.MailItem)
    Dim hasPDF As Boolean
    hasPDF = False ' 初始化标记,默认无PDF附件
    
    ' 先判断是否有附件
    If Item.Attachments.Count > 0 Then
        Dim attCount As Long
        Dim strFile As String
        Dim sFileType As String
        attCount = Item.Attachments.Count
        
        ' 遍历所有附件
        For i = 1 To attCount
            strFile = Item.Attachments.Item(i).FileName
            sFileType = LCase$(Right$(strFile, 4)) ' 取后缀4位转小写,匹配.pdf
            If sFileType = ".pdf" Then
                hasPDF = True ' 找到PDF,修改标记
                Exit For ' 无需继续遍历
            End If
        Next i
    End If
    
    ' 没有PDF附件的情况,移动到Reply文件夹
    If hasPDF = False Then
        Item.Move Session.GetDefaultFolder(olFolderInbox).Folders("Reply")
    End If
    
endsub:
    Set Item = Nothing
End Sub
  • 请提前在Outlook收件箱根目录下创建名为Reply的文件夹,避免运行时找不到目标文件夹报错
  • 脚本触发方式和你之前的配置一致,通过Outlook规则设置新邮件到达时调用该宏即可
  • 代码兼容大小写不同的PDF后缀(比如.PDF、.Pdf都会被识别为合法附件)

内容的提问来源于stack exchange,提问作者Peacescript

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 19:06:05