I got this Error Message after opening an Excel file by simply double-clicking it.
-------------------------------------
File in Use
Filename.xls is locked for editing
by 'Author'.
Open 'Read-Only' or, click 'Notify' to open read-only and receive notification when the document is no longer in use.
-------------------------------------
Apparently, the error msg states it clearly.
The excel file I am opening is used at that time.
What I only did was open a workbook of an excel file using Access VBA.
Here's the code:
-------------------------------------
Private Function Open_xlFile() As Object
Dim oXL As Object
Dim oExcel As Object
Dim sFullPath As String
Dim sPath As String
Set oXL = CreateObject("Excel.Application")
On Error Resume Next
oXL.UserControl = True
On Error GoTo 0
On Error GoTo ErrHandle
sFullPath = CurrentProject.Path & EXCEL_FOLDER & "\Filename.xls"
With oXL
.Visible = False
.Workbooks.Open (sFullPath)
End With
ErrExit:
Set oXL = Nothing
Exit Function
ErrHandle:
oXL.Visible = False
MsgBox Err.Description
GoTo ErrExit
End Function
-------------------------------------
I opened the excel file using this.
After that, I opened the same excel file by double-clicking it
and the error msg appeared.
I think this code opened the excel file but didn't close it.
Is there something wrong with this code?
I set oXL to Nothing already.
What should be done to close the excel file?
(Need good help from the experts here)
-------------------------------------
File in Use
Filename.xls is locked for editing
by 'Author'.
Open 'Read-Only' or, click 'Notify' to open read-only and receive notification when the document is no longer in use.
-------------------------------------
Apparently, the error msg states it clearly.
The excel file I am opening is used at that time.
What I only did was open a workbook of an excel file using Access VBA.
Here's the code:
-------------------------------------
Private Function Open_xlFile() As Object
Dim oXL As Object
Dim oExcel As Object
Dim sFullPath As String
Dim sPath As String
Set oXL = CreateObject("Excel.Application")
On Error Resume Next
oXL.UserControl = True
On Error GoTo 0
On Error GoTo ErrHandle
sFullPath = CurrentProject.Path & EXCEL_FOLDER & "\Filename.xls"
With oXL
.Visible = False
.Workbooks.Open (sFullPath)
End With
ErrExit:
Set oXL = Nothing
Exit Function
ErrHandle:
oXL.Visible = False
MsgBox Err.Description
GoTo ErrExit
End Function
-------------------------------------
I opened the excel file using this.
After that, I opened the same excel file by double-clicking it
and the error msg appeared.
I think this code opened the excel file but didn't close it.
Is there something wrong with this code?
I set oXL to Nothing already.
What should be done to close the excel file?
(Need good help from the experts here)