I dont understand why I'm getting an out of range error on this.
I have a macro in my personal.xls workbook which runs when it opens (so essentially when excel starts this macro runs). It checks to see if a file is open, and if not, it opens it.
For some reason, I'm getting an error "out of range". The file still opens correctly, so I dont understand what this is all about...
I have a macro in my personal.xls workbook which runs when it opens (so essentially when excel starts this macro runs). It checks to see if a file is open, and if not, it opens it.
For some reason, I'm getting an error "out of range". The file still opens correctly, so I dont understand what this is all about...
Code:
Function IsWorkbookOpen(WorkbookName As String) As Boolean
Dim wb As Workbook
For Each wb In Excel.Workbooks
If UCase$(wb.Name) = UCase$(WorkbookName) Then
IsWorkbookOpen = True
Exit Function
End If
Next
End Function
Sub OPEN_MYFILE()
On Error GoTo ERRHANDLER
If IsWorkbookOpen("MYFILE.xls") = True Or IsWorkbookOpen("MYFILE.xls [Shared]") Then
MsgBox "MY FILE ALREADY OPEN"
Else
Workbooks.Open ("X:\xxxxxxxxx\MYFILE.xls") '<----out of range error
Run "HIDE_MYFILE"
End If
Exit Sub
ERRHANDLER:
If Err.Number = 1004 Then
Exit Sub
Else
MsgBox "UNKNOWN ERROR"
End If
Exit Sub
End Sub