简体   繁体   English

VBA无法在outlook中使用.Find查找电子邮件

[英]VBA can't find emails in outlook using .Find

I created a macro that works great on my computer. 我创建了一个在我的计算机上运行良好的宏。 When I upload and run it on another computer, it can't find any emails. 当我在另一台计算机上上传并运行它时,它找不到任何电子邮件。

Set olApp = GetObject(, "Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
Set olItms = olFldr.Items
Set olEmail = olApp.CreateItem(olMailItem)


 Set OutApp = CreateObject("Outlook.Application")
 Set OutMail = OutApp.CreateItem(0)


            subj = "Test email"

                Set olMi = olItms.Find("[Subject] = " & Chr(34) & subj & Chr(34))
              If Not (olMi Is Nothing) Then
                        For Each olAtt In olMi.Attachments
              Else
                  ' ends up here everytime

I sent myself an email called "Test email" and I can see it in my outlook inbox but my macro can never find it( on any computer I upload the macro to). 我给自己发了一封名为“测试电子邮件”的电子邮件,我可以在我的Outlook收件箱中看到它但我的宏却找不到它(在我上传宏的任何计算机上)。 However when I run the program on the original computer I wrote the program on, it works fine. 但是,当我在原始计算机上运行程序时,我编写了程序,它工作正常。 Not really sure what the issue is. 不确定问题是什么。

尝试搜索PR_NORMALIZED_SUBJECT MAPI属性:

set olMi = olItms.Find("@SQL=""http://schemas.microsoft.com/mapi/proptag/0x0E1D001F"" = '" & subj & "'")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM