0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

notes

Posted at

Function IsExcelFileOpen(filePath As String) As Boolean
Dim excel As Variant
Dim wb As Variant
Dim isOpen As Boolean
isOpen = False

On Error Resume Next
Set excel = GetObject(, "Excel.Application") ' 既存のExcelインスタンスを取得
If Not excel Is Nothing Then
    Forall book In excel.Workbooks
        If book.FullName = filePath Then
            isOpen = True
            Exit Forall
        End If
    End Forall
End If
On Error GoTo 0

IsExcelFileOpen = isOpen

End Function

Function IsFileLocked(filePath As String) As Boolean
Dim fileNum As Integer
Dim isLocked As Boolean
fileNum = Freefile()

On Error Resume Next
Open filePath For Binary Access Read Write Lock Read Write As #fileNum
If Err <> 0 Then
    isLocked = True
Else
    isLocked = False
    Close #fileNum
End If
On Error GoTo 0

IsFileLocked = isLocked

End Function

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?