kann mir jemand sagen, ob es möglich ist, eine Arbeitsmappe so einzustellen, dass sie exclusiv ausgeführt wird und nicht als weiteres Fenster in einer bereits geöffneten Arbeitsmappe erscheint?
Vielen Dank im Voraus
Ansgar
Sub Main()
Dim xlApp As New Excel.Application
On Error Resume Next
xlApp.Visible = False
xlApp.Workbooks.Open "C:\vb\test.xls"
If Err.Number > 0 Then MsgBox "Fehler beim Öffnen der Datei!"
Set xlApp = Nothing
End
Wenn nicht, kannst du im Code der Arbeitsmappe prüfen, ob andere Mappen geöffnet sind. Wenn ja, öffnet sich die Mappe selbst in einer neuen Instanz und schließt sich dann in der Instanz, in der es nicht alleine geöffnet ist.Option Explicit
Private Sub Workbook_Open()
Dim n As String
If Workbooks.Count > 1 Then
Application.EnableEvents = False
With ThisWorkbook
.Saved = True
.ChangeFileAccess Mode:=xlReadOnly
n = .FullName
End With
Application.EnableEvents = True
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
On Error Resume Next
xlApp.Workbooks.Open Filename:=n
If Err.Number > 0 Then
xlApp.Quit
Else
xlApp.Application.Visible = True
End If
Set xlApp = Nothing
ThisWorkbook.Close
End If
End Sub
Gruß Matthias