1

使用 Office 2010。

在访问中,我有一个包含客户联系信息的表格。

客户电子邮件旁边的按钮OPENS OUTLOOK并应用过滤器以在OUTLOOK中仅显示来自该客户的电子邮件。

Private Sub filterOutlook_Click()
   'bit of code here which checks if outlook is open, if not then"
   Shell "Outlook.exe /cleanviews"

   'email of contact field(hyperlink) is retreived
   contactname = Left$([E-mail contact].Value, InStr([E-mail contact].Value, "#") - 1)

   filtermail contactname
End Sub

过滤邮件功能如下:

Public Sub filtermail(name As String)

Dim objView As View
Set objView = outlook.ActiveExplorer.CurrentView

    If LenB(name) = 0 Then
        objView.Filter = vbNullString
    Else
        objView.Filter = _ 
        "http://schemas.microsoft.com/mapi/proptag/0x0065001f CI_STARTSWITH '" & name & "'"
    End If

objView.Save
objView.Apply

End Sub

该代码工作正常,但仅将过滤器应用于当前在OUTLOOK中打开的文件夹。

如果您有多个帐户,则必须先打开收件箱或已发送文件夹,然后应用过滤器。比较麻烦。

我想将上面的代码替换为可以在 Outlook 中控制搜索栏的代码。 搜索栏

因此,选择“所有邮件项目”或“所有 Outlook 项目”,按帐户或日期对结果进行排名,并使用以下查询“system.structuredquery.virtual.from:(name)”和“to:(name)”。

手动使用搜索栏会给我想要的结果。我可以跨不同帐户和文件夹查看客户的所有历史记录。但是让它自动化会很棒。

有可能吗,我怎样才能做到这一点。

总而言之:当单击电子邮件旁边的按钮时,打开 Outlook 并显示来自该电子邮件的消息。

谢谢

4

1 回答 1

1

找到了:

Public Sub filtermail(name As String)

Dim myOlApp As New outlook.Application

    If LenB(name) = 0 Then
        myOlApp.ActiveExplorer.ClearSearch
    Else
        myOlApp.ActiveExplorer.Search "from:(" & name & ") OR to:(" & name & ")", olSearchScopeAllFolders
    End If

Set myOlApp = Nothing
End Sub

需要一些测试,但现在可以使用。要调用函数/子,请参阅第 1 篇文章中发布的代码。

于 2012-04-15T21:07:57.330 回答