--------- 编辑以下 Remou 的评论 ---------
新代码:
Sub test()
Dim myInspectors As Outlook.Inspectors
Dim x As Integer
Dim iCount As Integer
Set myInspectors = Application.Inspectors
iCount = Application.Inspectors.Count
If iCount > 0 Then
For x = 1 To iCount
'check for message only
If InStr(1, myInspectors.Item(x).Caption, "Message (HTML)") > 0 Then
' MsgBox myInspectors.Item(x).EntryID
MsgBox myInspectors.Item(x).Caption
End If
Next x
Else
MsgBox "No inspector windows are open."
End If
End Sub
然而,一些警告:
- 我没有找到访问检查器的源对象(即消息)以检查这是否是消息的方法
- 我也没有找到访问 EntryID 的方法(因为它是 Message 属性而不是检查器属性)。
感谢 Remou 指出一些很棒的技巧(抱歉,我尝试了一下自己对 Outlook VBA 的实际了解)。
-------- 原答案 --------
这是一种遍历所有 Outlook 窗口的方法:
Option Explicit
Declare Function EnumWindows Lib "user32" (ByVal lpFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Public Function EnumWindProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim strTitle As String
Dim lngTemp As Long
strTitle = String(255, 0)
lngTemp = GetWindowText(hWnd, strTitle, 255)
If InStr(1, Left(strTitle, lngTemp), "Message (HTML)") > 0 Then
lngOutlookHWnd = hWnd
MsgBox (strTitle)
End If
EnumWindProc = 1
End Function
Public Sub GetOutlookHWnd()
EnumWindows AddressOf EnumWindProc, 0
End Sub
改编自this thread
但是,您仍然需要找到一种方法来存储消息(可以使用 Remou 建议的 EntryID)以便之后重新打开它。
如果您找到完整的工作解决方案,请告诉我们。