vba 如何从 MS Access 2007 将 MS Outlook 2007 对话框置于最前面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5663961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I bring an MS Outlook 2007 dialog to the front from MS Access 2007?
提问by Randall
I am attempting to allow a user of a MS Access 2007 database to select another user from the MS Outlook GAL. I currently have working code that opens the Outlook Select Names Dialog, but it hides behind the database window until a user clicks on Outlook.
我试图允许 MS Access 2007 数据库的用户从 MS Outlook GAL 中选择另一个用户。我目前有打开 Outlook 选择名称对话框的工作代码,但它隐藏在数据库窗口后面,直到用户单击 Outlook。
How do I make the dialog visible to the user in VBA?
如何在 VBA 中让用户看到对话框?
Here's my code for the dialog (typos are a result of a manual copy--this code is on an airgapped network):
这是我的对话框代码(拼写错误是手动复制的结果 - 此代码位于气隙网络上):
set OLApp = CreateObject("Outlook.Application")
set OLDialog = OLApp.Session.GetSelectNamesDialog
with OLDialog
.SetDefaultDisplayMode olDefaultSingleName
if .Display then
if OLDialog.Recipients.Count then
theUser = OLDialog.Recipients.Item(1)
end if
end if
end with
回答by Randall
I made this work by adding the following line after .SetDefaultDisplayMode olDefaultSingleName
:
我通过在以下行之后添加以下行来完成这项工作.SetDefaultDisplayMode olDefaultSingleName
:
OLApp.ActiveWindow.Activate
回答by greatquux
Thanks alot Randall! I've also found that if Outlook isn't actually opened that won't work because ActiveWindow will be null, so wrapping it up like this helps too:
非常感谢兰德尔!我还发现,如果 Outlook 没有实际打开,那将无法工作,因为 ActiveWindow 将为空,所以像这样包装它也有帮助:
If Not (oApp.ActiveWindow Is Nothing) Then 'only if there's a window
oApp.ActiveWindow.Activate 'make sure outlook comes to foreground first
End If