有没有办法可以在自动搜索 Outlook 的访问数据库上创建一个按钮?我的想法是除了可以单击的电子邮件地址之外还有一个按钮,它将打开 Outlook,或者如果打开,则跳转到 Outlook,并在所有项目中搜索客户的电子邮件地址?
问问题
578 次
1 回答
2
下面是一个 VBA 子程序,它采用搜索字符串并在 Outlook 的现有实例中搜索或创建一个新实例进行搜索。在 Office 2010 中测试。如果要被其他人使用,则值得放入一个真正的错误处理程序。
您需要参考“Microsoft Outlook 14.0 对象库”或您拥有的任何版本。您可以通过工具->参考在 VBA 窗口中执行此操作。
如果您喜欢,可以借助AdvancedSearch方法在 Access 本身中显示搜索结果。
Sub outlookSearch(searchString As String)
Dim app As Outlook.Application
'This will throw an error if there's no instances of Outlook running
' so resume after the error.
On Error Resume Next
Set app = GetObject(, "Outlook.Application")
On Error GoTo 0 'Replace this with a real error handler
'If the app variable is empty
If app Is Nothing Then
'Create a new instanc eof outlook
Set app = CreateObject("Outlook.Application")
'Add an explorer showing the inbox
app.Explorers.Add app.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
'Make the explorer visible
app.Explorers(1).Activate
End If
'Search all folders for searchString
app.ActiveExplorer.search searchString, olSearchScopeAllFolders
Set app = Nothing
End Sub
于 2011-08-20T00:54:40.250 回答