OUTLOOK vba filter with like statement

别等时光非礼了梦想. 提交于 2020-07-09 08:32:19

问题


I want to put a like statement as I want to filter email that starts with tmeadmin@

This code breaks on the line with the like statement. How do I fix it?

 Dim objOutlook As Outlook.Application
    Dim objNamespace As Outlook.NameSpace
    Dim objSourceFolder As Outlook.MAPIFolder
    Dim objDestFolder As Outlook.MAPIFolder
    Dim InboxMsg As Object
    Dim Inbox As Outlook.Folder
    Set objOutlook = Application
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set Inbox = objNamespace.GetDefaultFolder(olFolderInbox)
    Dim myRestrictItems As Outlook.Items
     Dim filter As String
     filter = "urn:schemas:httpmail:fromemail LIKE 'tmeadmin@%'"

      MsgBox (filter)
 Set myRestrictItems = Inbox.Items.Restrict(filter)

回答1:


To use the LIKE operator, you need to use the @SQL syntax:

filter = "@SQL=urn:schemas:httpmail:fromemail LIKE 'tmeadmin@%'"


来源:https://stackoverflow.com/questions/52060372/outlook-vba-filter-with-like-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!