2009-09-01 6 views
1

J'utilise le ROT pour rechercher des instances MSWord actives. Dans certaines versions de Word, le document n'est pas enregistré dans la table, à la place il est enregistré en tant que modèle NORMAL et donc je ne peux pas trouver le document par son titre comme documenté par microsoft. Quelqu'un sait-il un correctif pour cela?Automatisation de mots et table d'objets en cours d'exécution

Répondre

0

Est-ce que l'API FindWindowPartial vous est utile? Il vous permettra de rechercher des fenêtres avec Microsoft Word dans le titre.

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 
Questions connexes