Delete operations done using FileSystemObject are permanent and cannot be undone. The FileSystemObject gets discarded after the End With system and hence, no cleanup is needed. StrPath = "C:\myPath\NewTextDocument.txt" You need to add a reference to the “Microsoft Scripting Runtime” library under Tools > References. This is a compact way to achieve the result in example 2. Set ObjFso = CreateObject("Scripting.FileSystemObject")Ĭall Delete_File("D:StuffBusinessTempTempfile.xlsx") Private Sub Delete_File( ByVal strPath As String) If the file is open, the error handler will catch the error: The function below receives as input a string path it tries to delete it. This can be prevented by using error handlers. Another error that you may encounter when trying to delete a file using VBA, is the Run-time Error ’70’ Permission Denied error.
0 Comments
Leave a Reply. |