简体   繁体   中英

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). 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 & "'")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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