Stop searching. Start learning and developing your excel skills.
Macro
VBA
Formula
Function
Shortcut
Tricks

» » VBA Function To Check If File Is Opened

VBA Function To Check If File Is Opened

June 03, 2017 |
This is also related to below queries:
  1. excel vba check if workbook is open
  2. isfileopen vba
  3. excel vba check if workbook is open by another user
  4. vba check if workbook is open and if not open it
  5. isworkbookopen vba
  6. excel vba check if workbook open then close
The Code:
Function IsFileOpen(filename As String)
    Dim filenum As Integer, errnum As Integer
    On Error Resume Next
    filenum = FreeFile()
    Open filename For Input Lock Read As #filenum
    Close filenum
    errnum = Err
    On Error GoTo 0
    Select Case errnum
        Case 0
         IsFileOpen = False
        Case 70
            IsFileOpen = True
        Case Else
 
    End Select
End Function
If Not IsFileOpen("FileDirectoryToOpen") Then
    Workbooks.Open "FileDirectoryToOpen"
End If
Where:

FileDirectoryToOpen = complete path if your file name. The file must consist of file extension. Example: For Excel, must ended with .XLSX

No comments:

Post a Comment