Hi!
I've been using the below piece of code successfully before
However, when I ran the macro today, I got a warning saying: "Ambiguous name detected: IsFileOpen". I don't understand why, because I didn't change anything in the code.
Can someone please explain?
I've been using the below piece of code successfully before
VBA Code:
.
.
.
Dim myPath As String
myPath = ThisWorkbook.Path & Application.PathSeparator 'Change path
If IsFileOpen(myPath & "IzborQ.xlsx") = True Then
MsgBox ("File is already opened")
Else
MsgBox ("File is not opened yet")
Workbooks.Open (myPath & "IzborQ.xlsx")
End If
.
.
.
VBA Code:
Function IsFileOpen(fileFullName As String)
Dim FileNumber As Integer
Dim errorNum As Integer
On Error Resume Next
FileNumber = FreeFile() ' Assign a free file number.
' Attempt to open the file and lock it.
Open fileFullName For Input Lock Read As #FileNumber
Close FileNumber ' Close the file.
errorNum = Err ' Assign the Error Number which occured
On Error GoTo 0 ' Turn error checking on.
' Now Check and see which error occurred and based
' on that you can decide whether file is already
' open
Select Case errorNum
' No error occurred so ErroNum is Zero (0)
' File is NOT already open by another user.
Case 0
IsFileOpen = False
' Error number for "Permission Denied." is 70
' File is already opened by another user.
Case 70
IsFileOpen = True
' For any other Error occurred
Case Else
Error errorNum
End Select
End Function
However, when I ran the macro today, I got a warning saying: "Ambiguous name detected: IsFileOpen". I don't understand why, because I didn't change anything in the code.
Can someone please explain?