ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting a file on C drive using VBA (https://www.excelbanter.com/excel-programming/282823-deleting-file-c-drive-using-vba.html)

Todd Huttenstine[_2_]

Deleting a file on C drive using VBA
 
I need to delete the file C:\Sheets.xls using VBA.
How do I do this?

Thank you
Todd Huttenstine

Dave Peterson[_3_]

Deleting a file on C drive using VBA
 
Take a look at the Kill command in Help.



Todd Huttenstine wrote:

I need to delete the file C:\Sheets.xls using VBA.
How do I do this?

Thank you
Todd Huttenstine


--

Dave Peterson


Todd Huttenstine[_2_]

Deleting a file on C drive using VBA
 
Below is the code I used and its closing the file, not
deleting the file.


Kill "c:\sheets.xls"

-----Original Message-----
Take a look at the Kill command in Help.



Todd Huttenstine wrote:

I need to delete the file C:\Sheets.xls using VBA.
How do I do this?

Thank you
Todd Huttenstine


--

Dave Peterson

.


Todd Huttenstine[_2_]

Deleting a file on C drive using VBA
 
nevermind I got it.


-----Original Message-----
Take a look at the Kill command in Help.



Todd Huttenstine wrote:

I need to delete the file C:\Sheets.xls using VBA.
How do I do this?

Thank you
Todd Huttenstine


--

Dave Peterson

.


Jake[_7_]

Deleting a file on C drive using VBA
 
Untested air code (needs reference to Microsoft Scripting Runtime Library [scrrun.dll]):

Dim fso as FileSystemObject
Dim f as File

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile("C:\Sheets.xls")

f.Delete

Set f = Nothing
Set fso = Nothing

Hope this helps!

Jake
----- Todd Huttenstine wrote: -----

Below is the code I used and its closing the file, not
deleting the file.


Kill "c:\sheets.xls"

-----Original Message-----
Take a look at the Kill command in Help.
Todd Huttenstine wrote:
I need to delete the file C:\Sheets.xls using VBA.

How do I do this?
Thank you

Todd Huttenstine
--
Dave Peterson


.


Pete McCosh[_5_]

Deleting a file on C drive using VBA
 
Todd,

The Kill command wont work if you have the file you want
to kill open, as I presume you must have, otherwise you
couldn't close it!

Pete


onedaywhen

Deleting a file on C drive using VBA
 
"Jake" wrote in message ...
Untested air code (needs reference to Microsoft Scripting Runtime Library [scrrun.dll]):

Dim fso as FileSystemObject
Dim f as File


Change these declarations to 'As Object' and the reference is not needed.

Dave Peterson[_3_]

Deleting a file on C drive using VBA
 
Actually, you can kill that open workbook:

This was posted by Jim Rech:

Sub testme()

With ThisWorkbook
.Saved = True
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With

End Sub

(make sure you have backups!)



Pete McCosh wrote:

Todd,

The Kill command wont work if you have the file you want
to kill open, as I presume you must have, otherwise you
couldn't close it!

Pete


--

Dave Peterson



All times are GMT +1. The time now is 08:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com