[ERROR MSG] File in Use : Filename.xls is locked for editing

keirnus

Registered User.
Local time
Tomorrow, 06:20
Joined
Aug 12, 2008
Messages
99
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)
 
Got this already!

Oh well, seems like I'm answering my questions by myself today...hee!
(Where did the "answerers" go?)

I added this to the code:
oXL.Application.Quit

So, something in the code should look like this:
----------------------------------------------
...................

With oXL
.Visible = False
.Workbooks.Open (sFullPath)
End With

ErrExit:
oXL.Application.Quit
Set oXL = Nothing
Exit Function

...................
----------------------------------------------

I'm not sure if it should be after "ErrExit:" but that's where I'm adding it.

With the added line, the error message just disappeared.
Guess it closes the hidden instance after opening the excel file.
 
That is where you would want to put it.

Not sure but is there not a oXL.Close or oXL.Workbooks.Close?
 
Hello CyberLynx,


oXL.Workbooks.Close also works.
That and oXL.Application.Quit both work.

But I'm using both now to make sure no instance of excel is left behind. (hehe)

By the way, oXL.Close doesn't work because there's no such property.
Just tried it a while ago.

Thanks for the reply. =)
 

Users who are viewing this thread

Back
Top Bottom