AW: Wechsel zwischen Anwendungen mit VBA
04.01.2007 16:03:39
Ramses
Hallo
Sorry, ich dachte du verwendest den SHELL- Befehl.
Mit DDE kann ich hier leider nix anfangen :-(
Daher die Frage noch auf offen.
Ich würde an Deiner Stelle eine API Funktion verwenden, die vorher das Handle für das Aktive EXCEL Window zurückgibt, das kannst du nach dem DDE Befehl dann wieder in den Vordergrund bringen.
Musst du mal probieren
Option Explicit
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal wIndx As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function SetActiveWindow Lib "User" (ByVal hwnd As Integer) As Integer
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Const HWND_Top = 0
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const FLAGS = 0 'SWP_NOMOVE Or SWP_NOSIZE
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const GWL_STYLE = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Public Sub GetWindowBack()
Dim hwnd As Long, sTitle As String, lStyle As Long, Task_name() As String
Dim myApplication
Dim count As Integer, index As Integer, gefunden As Boolean
hwnd = FindWindow(ByVal 0&, ByVal 0&)
hwnd = GetWindow(hwnd, GW_HWNDFIRST)
Do
lStyle = GetWindowLong(hwnd, GWL_STYLE)
lStyle = lStyle And (WS_VISIBLE Or WS_BORDER)
sTitle = GetWindowTitle(hwnd)
'Sucht in den gerade geöffneten Fenster nach einem
'Fenster mit dem Teilstring "TabellenNammen"
If Trim(sTitle) <> "" And InStr(UCase(sTitle), UCase(ActiveWorkbook.Name)) <> 0 Then
MsgBox "Titel: " & sTitle & ", Instanznummer: " & hwnd
myApplication = SetWindowPos(hwnd, HWND_Top, 0, 0, 0, 0, FLAGS)
Exit Sub
End If
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop Until hwnd = 0
End Sub
Private Function GetWindowTitle(ByVal hwnd As Long) As String
Dim lResult As Long, sTemp As String
lResult = GetWindowTextLength(hwnd) + 1
sTemp = Space(lResult)
lResult = GetWindowText(hwnd, sTemp, lResult)
GetWindowTitle = Left(sTemp, Len(sTemp) - 1)
End Function
Gruss Rainer