Excel VBA附件搜索 [英] Excel vba attachment search

查看:71
本文介绍了Excel VBA附件搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究可在Outlook邮件附件中找到字符串的宏.我有一个工作模块,可以搜索给定邮箱和文件夹中的主题,正文和附件名称.

I am working on macro which would find string within outlook mails attachments. I have working module searching through subject, body and attachments names on given mailbox and folder.

问题是我的代码不想在附件函数中模拟Outlook搜索.

Problem is that my code don't want to emulate outlook search within attachment function.

代码在邮件主题字段中搜索单词"office"并显示找到的邮件:

Code searches for a word 'office' within mail subject field and displays found mails:

Sub t22()

Dim myolApp As Outlook.Application
Dim objNS As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Dim ProcessName As String
Dim EmailName As String

Set myolApp = CreateObject("Outlook.Application")
Set objNS = myolApp.GetNamespace("MAPI")
Set objFolder = objNS.Folders("my@mailbox.com")
Set TargetInbox = objFolder.Folders("Inbox")

Dim oItms As Outlook.Items
Dim oItm As Outlook.MailItem
Set oItms = TargetInbox.Items
Dim sFilter As String
Dim EmailTime As String

sFilter = "@SQL=""http://schemas.microsoft.com/mapi/proptag/0x0037001f"" = 'office'"
Set oItm = oItms.Find(sFilter)
'If Not IsEmpty(oltm) Then
    oItm.Display
    Debug.Print oItm.Body
'End If
End Sub

据我了解,"sFilter"应指向目标搜索字段,但是当我将其值用于附件(0x0EA5001E)时,它将失败.

As far as I understand 'sFilter' should be referring to target search fields but when I use its value for attachments (0x0EA5001E) it fails.

我也在尝试AdvancedSearch方法,但结果相同-除附件外,其他所有功能都可以使用.

I was also trying AdvancedSearch method but with same result - working for everything other than attachment.

推荐答案

Outlook对象模型不提供任何用于搜索附件中的字符串的内容.您需要找到所有附加了文件的项目,然后遍历所有项目.进行迭代时,您可以打开附件并在其中搜索字符串.您可以使用以下搜索条件来查找所有带有附件的项目:

The Outlook object model doesn't provide anything for searching a string in attachments. You need to find all items that have files attached to them and then iterate over all of them. While iterating you can open the attached file and search for a string inside. You can use the following search criteria to find all items that have attachments:

 query ="@SQL=" & chr(34) & "urn:schemas:httpmail:hasattachment" & chr(34) & "=1"

您可能还会发现以下文章有所帮助:

You may also find the following articles helpful:

这篇关于Excel VBA附件搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆