Partial PublicClass ThisApplicationClass ThisApplication 'outlook的菜单栏 Dim _menuBar As Office.CommandBar =Nothing '创建菜单按钮 Dim _topMenu As Office.CommandBarPopup =Nothing '创建生成搜索文件夹的菜单 Dim _menuSearch As Office.CommandBarButton PrivateSub CreateSearch()Sub CreateSearch() '定义一个Search对象 Dim mailSearch As Outlook.Search Dim strFolder AsString Dim strSearch AsString '获得收件箱文件夹 Dim inbox As Outlook.MAPIFolder =Me.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) '获得已发送邮件文件夹 Dim sendbox As Outlook.MAPIFolder =Me.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail) '定义搜索范围 strFolder ="SCOPE ('shallow traversal of """& _ sendbox.FolderPath &""" ', 'shallow traversal of """& _ inbox.FolderPath &""" ')" '定义查询条件 strSearch ="urn:schemas:httpmail:fromemail LIKE '%fastid@21cn.net%' OR urn:schemas:httpmail:displayto LIKE '%fastid@21cn.net%'" mailSearch =Me.AdvancedSearch(strFolder, strSearch, True, "MySearch") mailSearch.Save("邮件查询") End Sub PrivateSub _menuSearch_Click()Sub _menuSearch_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault AsBoolean) CreateSearch() End Sub PrivateSub CreateMenus()Sub CreateMenus() _menuBar =Me.ActiveExplorer().CommandBars.ActiveMenuBar If (Not (_menuBar IsNothing)) Then Dim _control As Office.CommandBarControl '寻找学员信息管理菜单 ForEach _control In _menuBar.Controls If (_control.Caption ="学员信息管理") Then _topMenu = _control EndIf Next If (Not (_topMenu IsNothing)) Then '添加创建搜索的菜单 _menuSearch = _topMenu.Controls.Add(Office.MsoControlType.msoControlButton, _ Type.Missing, _ Type.Missing, _ Type.Missing, _ True) _menuSearch.Caption ="查询邮件" _menuSearch.Visible =True '添加菜单的点击事件处理 AddHandler _menuSearch.Click, AddressOf _menuSearch_Click EndIf EndIf End Sub End Class