Be the first user to complete this post

  • 0
Add to List

FileSystemObject : DeleteFile Method


This function Deletes a specific file.

Format : 

objectOfFileSystemObject. DeleteFile (filename [, force])

objectOfFileSystemObject : As the names says, it’s a FileSystemObject.

  • fileName
    • Mandatory
    • Type:     String
    • Name of the file to delete.
  •     overwrite
    • Optional
    • Type: Boolean ( True: delete the file even if read-only attribute is set , False(default): it not delete the file if read-only attribute is set)
Function FnDeleteFile(strFileName)
       Set fso = CreateObject("Scripting.FileSystemObject")

       fso. DeleteFile (strFileName)
End Function

Call FnDeleteFile ("c:\New Folder\File1.txt")

Also Read:

  1. FileSystemObject : GetAbsolutePathName Method
  2. FileSystemObject : FileExists Method
  3. FileSystemObject : CopyFile Method
  4. FileSystemObject : CreateFolder Method
  5. FileSystemObject : GetFileVersion Method
  6. Excel-VBA : Insert Multiple Images from a Folder to Excel Cells
  7. VBA-Excel: Add/Insert multiple objects from a folder in an Excel Document.
  8. FileSystemObject in Excel Macro