How do i capture the text in the Instant Search box in Outlook 2010 in vba

我是研究僧i 提交于 2020-01-05 09:35:41

问题


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

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?

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)"


回答1:


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

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

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 


来源:https://stackoverflow.com/questions/29846339/how-do-i-capture-the-text-in-the-instant-search-box-in-outlook-2010-in-vba

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