Deleting File

  • Thread starter Thread starter Powderfinger
  • Start date Start date
Use the VBA Kill() function.

Example:
Kill "C:\Test\*.txt"

Yes, it will accept the ? and * wild cards. If you try to delete an open
file (if the application that has it open locks it, Notepad doesn't), you'll
get error 70 (Permission Denied). If the file is Read Only, you'll get error
75 (Path/File access error). If the file is marked as Hidden or System,
you'll get error 53 (File not found).

You can use the SetAttr statement to remove the hidden, system, and read
only attributes from the file. Again, it won't work on an open, locked file.

Example:
SetAttr "C:\Test\MyFile.txt", vbNormal

The SetAttr statement will not accept the wild cards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top