benjamin132
New Member
- Joined
- Jun 8, 2022
- Messages
- 21
- Platform
- 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 :
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