Word自动化和运行对象表

时间:2009-09-01 16:21:58

标签: com automation ms-word

我正在使用ROT查找任何活动的MSWord实例。在某些版本的word中,文档没有在表中注册,而是注册为NORMAL模板,因此我无法通过microsoft记录的文档找到该文档。有人知道这个的修补程序吗?

1 个答案:

答案 0 :(得分:0)

FindWindowPartial API对您有用吗?它允许您在标题中搜索带有Microsoft Word的窗口。

Option Explicit

Private Const GW_HWNDNEXT = 2
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Function FindWindowPartial(ByVal Title As String) As String
    Dim hWndThis As Long

    hWndThis = FindWindow(vbNullString, vbNullString)
    While hWndThis
        Dim sTitle As String, sClass As String
        sTitle = Space$(255)
        sTitle = Left$(sTitle, GetWindowText(hWndThis, sTitle, Len(sTitle)))
        If InStr(sTitle, Title) > 0 Then
            FindWindowPartial = sTitle & "|" & FindWindowPartial
        End If
        hWndThis = GetWindow(hWndThis, GW_HWNDNEXT)
    Wend
End Function