ich möchte per VBA prüfen ob Mappe1 schon offen ist. Aber mein code stimmt nicht.
If Windows("Mappe1.xls").Activate Then
Exit Sub
End If
Danke für die Hilfe
Gruß Holger
Sub testWB()
Dim wb As Workbook
For Each wb In Application.Workbooks
If wb.Name = "Mappe1.xls" Then Exit Sub
Next
End Sub
Option Explicit
Sub test()
Debug.Print "Die Mappe 'Mappe1' ist bereits geöffnet: " & windowExists("Mappe1.xlsx")
End Sub
Private Function windowExists(ByVal wName As String) As Boolean
Dim xlApp As Application
Dim hWnd As Variant
Set xlApp = ThisWorkbook.Parent
On Error Resume Next
For Each hWnd In xlApp.Windows
If hWnd.Caption = wName Then
windowExists = True
Exit Function
End If
Next hWnd
End Function