kill an open Excel file

benjamin132

New Member
Joined
Jun 8, 2022
Messages
21
Platform
  1. Windows
Hi guys, I just want to kill a file even if he is open. I saw on forums that i just need to save file before kill it but doesn't work i have the error 70 permission denied.
Someone know how to do that ?
Sry for my english i am a young french boy who just want learn vba :D
Here is my code :
VBA Code:
Sub supprfiles()
    Dim i As Integer
    Dim MyFile As Object
    Dim MyFSO As Object
    Dim MyFolder As Object
    Dim MyFiles As Object
    Dim supr As String
    Dim Workbook As Workbook
    Set MyFSO = CreateObject("Scripting.FileSystemObject")
    Set MyFolder = MyFSO.GetFolder("C:\Users\bob\Documents\excel")
    Set MyFiles = MyFolder.Files
    i = 1
    For Each Workbook In Application.Workbooks
        Workbook.Save
    Next
    For Each MyFile In MyFiles
        supr = "C:\Users\bob\Documents\excel\" & MyFile.Name
        Kill supr
        i = i + 1
    Next MyFile
    
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
you cannot 'kill' a file if the user is in it.

you can:
if on the network:
run: computer management
(left pane) expand shared folders
expand OPEN FILES
select the files open
right-click , close all files

then you can delete (kill) them.

or ----
run TASK MANAGER , close the app in the processes list.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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