如何最大化并将重点放在打开的Outlook电子邮件的前景上?
我正在使用以下代码打开电子邮件项目(特定条件)。
之后,我需要最大化打开的Outlook电子邮件窗口,并将重点设置为前景。
Option Explicit
Option Compare Text
Public WithEvents MyItem As Outlook.MailItem
Public EventsDisable As Boolean
Private Sub Application_ItemLoad(ByVal Item As Object)
If EventsDisable = True Then Exit Sub
If Item.Class = olMail Then
Set MyItem = Item
End If
End Sub
Private Sub myItem_Open(Cancel As Boolean)
EventsDisable = True
If MyItem.Subject = "Auto Plan" And Application.ActiveExplorer.CurrentFolder.Name = "MyTemplate" Then
'Code to maximize the opened outlook email window and set focus for it to be foreground
End If
EventsDisable = False
End Sub
以下Windows API功能
#If Win64 Then
Private Declare PtrSafe Function SetForegroundWindow Lib "user32" _
(ByVal hWnd As LongPtr) As LongPtr
#Else
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hWnd As Long) As Long
#End If
Public Sub Bring_to_front()
Dim setFocus As Long
setFocus = SetForegroundWindow(xxxxxxx.hWnd)
End Sub
感谢您的任何有用的评论和答案。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
调用
mailItem.display
,然后通过调用boce> Inspector> Inspector.activate
来激活Inspector
对象。Inspector
可以从mailItem.getInspector
中检索对象。要记住的一件事是,如果父进程不在前景中,窗户不会将窗户带到前景。您需要使用
attactthreadinput
函数 - 请参见 332059Call
MailItem.Display
, then activate theInspector
object by callingInspector.Activate
.Inspector
object can be retrieved fromMailItem.GetInspector
.One thing to keep in mind is that Windows will not bring a window to the foreground if the parent process is not in the foreground. You would need to use
AttachThreadInput
function for that - see https://stackoverflow.com/a/17793132/332059您可以使用 activate 或
Inspector
从Outlook对象模型类。为了最大化窗口,您可以使用 showwindow从Windows API中的方法,这是VBA中可能的声明:
因此,您需要传递窗口句柄,而SW_Maximimime值则作为第二个参数以最大化窗口。请参阅如何最小化/最大化打开的应用程序以获取更多信息。
You can use the SetForegroundWindow method which brings the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user. Alternatively you may consider using the Activate method of the Explorer or
Inspector
classes from the Outlook object model.To maximize the window you could use the ShowWindow method from Windows API, here is a possible declaration in VBA:
So, you need to pass a window handle and the SW_MAXIMIZE value as the second parameter to maximize the window. See How to minimize/maximize opened Applications for more information.
为了激活“ 打开的Outlook电子邮件消息窗口”,您需要“确定其句柄”。为此,您可以使用其标题。
中复制下一个API函数:
1.a请在同一标准模块 变量对于供应,保存和使用必要的窗口句柄(在注册表中/从注册表中)
myitem_open 以下一个方式:
3.1如果必须从 的VBA中显示邮件窗口,则应用程序,从上方的声明和API函数也必须在模块的顶部复制,以保留必要的(以下)子。
3.2复制下一个改编的
sub
并运行它(在Outlook中显示必要的邮件窗口后,当然... ):请尝试并发送一些反馈。
In order to activate "the opened outlook email message window" you need to "determine its handle". In order to do that you may use its caption.
1.a Please copy the next API functions in the same standard module:
The above variables are necessary to supply, save and use the necessary window handle (in/from Registry)
myItem_Open
in the next way:3.1 If the mail window must be shown in foreground from VBA of another application, the declarations and API functions from above, must be also copied on top of the module keeping the necessary (following) sub.
3.2 Copy the next adapted
Sub
and run it (after showing the necessary mail window in Outlook, of course...):Please, try it and send some feedback.