Hi,
The following code works great as long as you have entered a manual file path.
Sub Test1()
Const strPDFpath As String = "P:\Project XLSM\NEW PROJECTS\_TEST_EXAMPLES\TEST_Check if PDF is Open and Close\Signed Agreement.pdf"
Dim wbk As Workbook, ws As Worksheet
If IsFileOpen(strPDFpath) = True Then
MsgBox "File is open!"
Else
MsgBox "File is not open!"
End If
End Sub
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
Error ErrNum
End Select
End Function
How can this be amended to work with "ThisWorkbook.Path", "ActiveWorkbook.Path", "Range("YOUR_NAMED_RANGE").Value", or some other type of variable?
Bookmarks