Excel document refuses to be deleted or altered

zeekmcphee

New Member
Joined
Feb 27, 2018
Messages
25
Office Version
  1. 2016
Platform
  1. Windows
Hi all,
I have been using an excel file to feed into a visual basic project,I have done this many times but have never encountered the following problem.
First the file has taken it upon itself,without any apparent reason to become a read only file,why I dont quite know,I didn't alter the file in any way and spent most of yesterday applying all the "suggestions"on the internet(including the MS site) to getting rid of read only,none of which worked.One of the popular suggestions was re-name the file,but then I would have to alter all of my calling code in the vb.net project each and everytime I used it .
In the end I thought I would go along with the suggestion of re-namimg, but it wont let me.it comes up with the message
"The action can't be completed because the file is open in Microsoft Excel"

But it isn't open in anything,including the vb project that it was originally a part of.
I rebooted the computer(several times) and tried opening the file but still the same old message.
I then decided to delete the file,but I get the same message about the action can't be completed etc.
Is this a common occurence,a file that is unalterable and undeletable,or could it pssibly be a virus,although I have run AVG and MB.
any suggestions most welcome
ZM
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try starting in Safe Mode and then deleting the file. Possibly some registry setting is corrupt leading Windows to think the file is open so cannot be deleted
 
Upvote 0
Hi,

I doubt very much it is virus related. It is possible the virus scanner has it locked after a scan though.
You could try temporarily turning it off.

Locked files are not limited to Excel. I would say I see it maybe half a dozen times a year.
I use a program called Unlocker (ver 1.9.2)
It will indicate if there is a program related lock and will unlock it for you and if it doesn't find a lock it has the option to delete the file.
It hasn't failed to do one or the other for me yet.

http://www.softpedia.com/get/System/System-Miscellaneous/Unlocker.shtml

Have a look here for transferring the project to possibly save the code.

https://www.mrexcel.com/forum/excel-questions/1047738-can-t-find-project-library.html
 
Last edited:
Upvote 0
Hi Both,
Thankyou for the replies.
The LockHunter is very hit and miss,it also opens the file minus the menu's at the top of the screen(apart from the formula bar) and it wont allow me to make any changes to the file or save it,so that was back to square one really.

In safe mode I was able to modify the file and delete it so I had all privelages.I deleted it then went back into ordinary mode,re-created the file giving it the same name.I gave it the same name because that meant I didn't have to change the access string in my vb.net program.All the problem file does is that it acts as a supplier of student exam marks which I download into the DataGridView in my vb.net program.
Effectively therefore the original problem file had gone.so I thought.
Once created the new file worked as per normal.So I opened up my VB project,and it recognised the new file and everything was OK.
I then closed down VB.net and tried to open the new file,it flashed onto the screen for a split second,refuses to open.
It seems therefore that the file is somehow corrupted once it is used by the VB.net program
This is quite frustrating because these are supposed to be compatable technologies.
Any suggestions most welcome:)

LL
 
Upvote 0
The unlocker software is a tool for unlocking a handle on a file, which is basically the file being locked by an application so no other can use it until it is released by that application.
The file should not be open when you use the tool.

In this case unlocker would only allow you to do 2 things:

1. See if another application has the file locked and attempt to release the lock.
2. Delete the file

Safe Mode suggested by Stuart seems to have gotten you closer to a solution.

I don't know how you are using the file and the project but look at how the connection between the 2 is made and how it is terminated.
Does the vb.net project control opening of the file?
If so does it also close the file?
Is there any connection set up that isn't terminated correctly?
 
Upvote 0
Hi Dave,
Thanks for the reply.
Your suggestion about closing the file properly after use is interesting.There is an excel.quit at the end of the file.Here is the code in full,perhaps you can spot something I have done wrong

Code:
Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button28.Click
        Dim oExcel As Object = CreateObject("Excel.Application")
        Dim oBook As Object = oExcel.Workbooks.Open("C:\Users\John\Desktop\marks.xlsm")
        Dim oSheet As Object = oBook.Worksheets(1)
        Dim i As Integer
        Dim cell As String
        For i = 0 To AscW(examList.Items.Count.ToString()(i = i + 1)) - 1
                      cell = "I" & Convert.ToString(i + 1)         
            cell = oSheet.Range(cell).Value
            If cell = "" Then
                Exit For
            Else
                examList.Items.Add(cell)
            End If
        Next
        oExcel.Quit()
 
Upvote 0
My knowledge isn't great so whether that code is ok as is, I can't say.
But looking at it from an amateurs pov, you have created an instance of Excel, used it to open a workbook then quit excel before closing the workbook.
I would go the route of closing the workbook when you are finished as good practice, whether it fixes your issue or not.

Code:
oExcel.Workbooks.close()
oExcel.Quit()
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top