Hallo!
Wie kann ich mit VBA (Excel97) abfragen ob eine Datei schon geöffnet ist?
Dank & Gruss,
Stefan
Hallo!
Wie kann ich mit VBA (Excel97) abfragen ob eine Datei schon
geöffnet ist?
Dank & Gruss,
Stefan
Hi Stefan,
versuche sie noch einmal zu öffnen und fange gegebenenfalls den Fehler mit einer „On Error“ Beahndlung ab.
Ciao
Uwe
Hallo Uwe
versuche sie noch einmal zu öffnen und fange gegebenenfalls
den Fehler mit einer „On Error“ Beahndlung ab.
stimmt, vielen Dank!
Da ich aber faul war bzw. nicht viel Zeit habe, habe ich bei der Site, die ich in meinem obigen neuen Posting genannt habe, für Excel-files folgende Lösung gefunden:
Function WorkbookOpen(WorkBookName As String) As Boolean
’ returns TRUE if the workbook is open
WorkbookOpen = False
On Error GoTo WorkBookNotOpen
If Len(Application.WorkBooks(WorkBookName).Name) > 0 Then
WorkbookOpen = True
Exit Function
End If
WorkBookNotOpen:
End Function
Example:
If Not WorkbookOpen(„MyWorkbookName.xls“) Then
Workbooks.Open „MyWorkbookName.xls“
End If
Prüfung, ob eine Arbeitsmappe durch einen anderen Nutzer oder Anwendung benutzt wird:
Function FileAlreadyOpen(FullFileName As String) As Boolean
’ returns True if FullFileName is currently in use by another process
’ example: If FileAlreadyOpen(„C:\FolderName\FileName.xls“) Then…
Dim f As Integer
f = FreeFile
On Error Resume Next
Open FullFileName For Binary Access Read Write Lock Read Write As #f
Close #f
’ If an error occurs, the document is currently open.
If Err.Number 0 Then
FileAlreadyOpen = True
Err.Clear
'MsgBox „Error #“ & Str(Err.Number) & " - " & Err.Description
Else
FileAlreadyOpen = False
End If
On Error GoTo 0
End Function
Dank & Gruss,
Stefan