Hallo,
bei mir funktioniert es.
Leider liefert Word nicht wie Excel über Application.hWnd das Applicationshandle. Dann könnte man über die API-Funktion SetForegroundWindow das Fenster in den Vordergrund setzen.
Das Fenster mittels Findwindow und dem Klassennamen und/oder dem Captiontext zu ermitteln ist eher schlecht, da man sie bei den neueren Word nicht so richtig ohne Hilfsmittel ermitteln kann und *-Suche nicht unterstützt wird.
Bleibt also m.E. nur das Durchscannen....
Teste mal folgenden Code:
Code:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 |
|
Private Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function EnumWindows Lib "user32" (ByVal lpEnumFunc As LongPtr, _
ByVal lParam As LongPtr) As Long
Private Declare PtrSafe Function GetWindowTextA Lib "user32" ( _
ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As Long
Sub Click()
Set wordapp = CreateObject("word.Application")
wordapp.Documents.Add "C:\Users\....Meldung.docx"
wordapp.Visible = True
Call EnumWindows(AddressOf EnumWindowProc, ByVal 0&)
End Sub
Private Function EnumWindowProc(ByVal hwnd As LongPtr, lParam As LongPtr) As Long
' Scannt alle Fenster durch und stoppt beim Finden des gesuchten Fensters
Dim sWinTxt As String * 260
Call GetWindowTextA(hwnd, sWinTxt, 260) ' Fenstertext holen
If sWinTxt Like "* Word*" Then
SetForegroundWindow hwnd: Exit Function
End If
EnumWindowProc = 1 ' Weiterscannen
End Function
|
_________
viele Grüße
Karl-Heinz
|