繁体   English   中英

VB和Outlook-仅显示使用VB代码来自联系人的消息(来自访问权限)

[英]vb and Outlook - show only messages from contact using vb code(from access)

使用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

filtermail功能如下:

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并显示该电子邮件的来往消息。

谢谢

找到了:

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

需要进行一些测试,但现在可以使用。 要调用该功能/子,请参见第一篇文章中发布的代码。

暂无
暂无

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

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