Bildschirm teilen für Excel und Edge
01.06.2024 18:58:58
Oisse
ich möchte gerne folgendes realisieren:
Wenn sich eine UserForm öffnet, soll die Excelmappe auf die linke Bildschirmhälfte minimiert werden und gleichzeitig soll sich auf der rechten Bildschirmhälfte Microsoft Edge öffnen.
Wie muss der Code hierfür aussehen?
Folgendes habe ich bisher:
' Modulcode: modWindowManagement
#If VBA7 Then
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
#Else
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
#End If
Const SWP_NOZORDER As Long = &H4
Const SWP_SHOWWINDOW As Long = &H40
Diese Zeilen:
'
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
werden mir rot angezeigt.
Auch bei diesem Code:
Private Sub AdjustWindows()
Dim hwndExcel As LongPtr
Dim hwndEdge As LongPtr
Dim edgePath As String
Dim result As Long
Dim screenWidth As Long
Dim screenHeight As Long
' Bildschirmbreite und -höhe
screenWidth = Application.UsableWidth
screenHeight = Application.UsableHeight
' Fenstergriff der Excel-Anwendung ermitteln
hwndExcel = FindWindow("XLMAIN", Application.Caption)
' Excel-Fenster auf die linke Bildschirmhälfte setzen
result = SetWindowPos(hwndExcel, 0, 0, 0, screenWidth / 2, screenHeight, SWP_NOZORDER Or SWP_SHOWWINDOW)
' Pfad zu Microsoft Edge (anpassen, falls notwendig)
edgePath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
' Microsoft Edge starten
Shell edgePath, vbNormalFocus
' Kurze Pause, um Edge Zeit zum Starten zu geben
Application.Wait (Now + TimeValue("0:00:03"))
' Fenstergriff von Microsoft Edge ermitteln
hwndEdge = FindWindow("Chrome_WidgetWin_1", vbNullString)
' Edge-Fenster auf die rechte Bildschirmhälfte setzen
result = SetWindowPos(hwndEdge, 0, screenWidth / 2, 0, screenWidth / 2, screenHeight, SWP_NOZORDER Or SWP_SHOWWINDOW)
End Sub
kommt hier:
' Fenstergriff der Excel-Anwendung ermitteln
hwndExcel = FindWindow("XLMAIN", Application.Caption)
eine Fehlermeldung
Anzeige