使用like代替=时,Item.Restrict函数不起作用

时间:2019-07-03 15:33:50

标签: vba outlook outlook-vba outlook-filter

我正在创建一个宏,该宏将电子邮件附件拉到要打开和复制的文件夹中,当预定义主题名称(即永不更改)时,它可以100%完美地工作。

void Main()
{
    var localStorage = new LocalStorageService();
    var azureStorage = new AzureStorageService("TOKEN_VALUE");
}

public interface IStorageService
{
    string Store<T>(T obj);
    T Retrieve<T>(string reference);
}

public class LocalStorageService : IStorageService
{
    public LocalStorageService() { /* no parameters necessary */ }
    public T Retrieve<T>(string reference) => throw new NotImplementedException();
    public string Store<T>(T obj) => throw new NotImplementedException();
}

public class AzureStorageService : IStorageService
{
    public AzureStorageService(string token) { /* connect to Azure */ }
    public T Retrieve<T>(string reference) => throw new NotImplementedException();
    public string Store<T>(T obj) => throw new NotImplementedException();
}

但是,当我尝试限制预设的开头时,说每封电子邮件都以“ aaaaa”开头,则会导致自动错误,并显示以下代码:

' this works
Set oOlInbFiltered = oOlInb.Items.Restrict("[Subject] = " & SubjectName)

有帮助吗?

预期结果:无错误消息,文件夹中的文件。相反,我收到

  

运行时错误'-2147352567(800200009)':发生自动化错误异常。

1 个答案:

答案 0 :(得分:0)

尝试改用以下代码:

criteria = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like '" & PrefixName & "%'" 
Set oOlInbFiltered = oOlInb.Items.Restrict(criteria)