' Check if workbook is open
On Error Resume Next
Set wb1 = Workbooks(fname)
On Error GoTo 0
If wb1 Is Nothing Then
' If workbook was NOT open, it will open it
' it will use the parameter WbOpen to remember whether the workbook was open or not
Set wb1 = Workbooks.Open(fpath & "\" & fname, ReadOnly:=True)
WbOpen = False
Else
' If the workbook was open, we'll just assign the sheet and WbOpen
WbOpen = True
End If
' If the workbook was NOT open, close it with: If WbOpen = False Then daten.Close SaveChanges:=False