如何在 vba 中的 Outlook 2010 的“即时搜索"框中捕获文本 [英] How do i capture the text in the Instant Search box in Outlook 2010 in vba

查看:45
本文介绍了如何在 vba 中的 Outlook 2010 的“即时搜索"框中捕获文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我修改了一些我发现的代码,这将允许我创建一个功能区按钮来搜索回 60 天.

I've amended some code I found which will allow me to create a ribbon button to search back sixty days.

Sub LastSixtyDays()
    Dim myOlApp As New Outlook.Application
    Dim tDate As Date
    tDate = Now - 60
    txtsearch = "received: (" & Format(tDate, "dd/mm/yyyy") & ".." & Format(Now, "dd/mm/yyyy") & ")"
    myOlApp.ActiveExplorer.Search txtsearch, olSearchScopeCurrentFolder
    Set myOlApp = Nothing
End Sub

效果很好,但是我如何追加txtsearch"到即时搜索框的现有内容,就像点击有附件"、主题"、来自"搜索标签呢?

which works perfectly, but how do i append "txtsearch" to the existing contents of the Instant Search box just like the clicking on the "has attachments", "subject", "from" in the search tab does?

因此,如果From:bob"在即时搜索框中,单击我的按钮将导致From:bob received: (23/02/2015..24/04/2015)"

So, if "From:bob" is in the Instant Search box, clicking my button will result in "From:bob received: (23/02/2015..24/04/2015)"

推荐答案

Outlook 对象模型没有为此提供任何属性或方法.

The Outlook object model doesn't provide any property or method for that.

您可以尝试使用 CurrentView 文件夹或资源管理器类的属性,它返回一个 View 代表当前视图的对象.要获取当前资源管理器的视图的 View 对象,请使用 Explorer.CurrentView 而不是 Explorer.CurrentFolder 返回的当前 Folder 对象的 CurrentView 属性.例如:

You may try to use CurrentView property of the Folder or Explorer class which returns a View object representing the current view. To obtain a View object for the view of the current Explorer, use Explorer.CurrentView instead of the CurrentView property of the current Folder object returned by Explorer.CurrentFolder. For example:

Sub GetView() 
  'Creates a new view  
   Dim objName As NameSpace  
   Dim objViews As Views  
   Dim objView As View 
   Set objName = Application.GetNamespace("MAPI")  
   Set objViews = objName.GetDefaultFolder(olFolderInbox).Views  
   'Return a view called Table View  
   Set objView = objViews.Item("Table View") 
End Sub

TableView 类提供了过滤器 属性,它返回或设置 DAV 搜索和定位 (DASL) 语法中的字符串值,表示视图的当前过滤器.

The TableView class provides the Filter property which returns or sets a string value in DAV Searching and Locating (DASL) syntax, that represents the current filter for the view.

Private Sub FilterViewToLastWeek() 
  Dim objView As View 
  ' Obtain a View object reference to the current view.  
  Set objView = Application.ActiveExplorer.CurrentView  
  ' Set a DASL filter string, using a DASL macro, to show  
  ' only those items that were received last week.  
  objView.Filter = "%lastweek(""urn:schemas:httpmail:datereceived"")%"  
  ' Save and apply the view.  
  objView.Save  
  objView.Apply  
End Sub 

这篇关于如何在 vba 中的 Outlook 2010 的“即时搜索"框中捕获文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆