Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default 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

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default 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

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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


.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default 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.
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel 2003 file converted to .xlsm file when save to network drive Chris Excel Discussion (Misc queries) 3 January 23rd 08 02:56 PM
WINDOWS CANNOT OPEN THIS FILE IN A:\ DRIVE Hils Excel Discussion (Misc queries) 3 January 10th 06 02:24 PM
Can't one excel file on network drive? Mesak Excel Discussion (Misc queries) 0 October 11th 05 09:58 AM
File in C drive is always trying to access Drive A Andre Croteau Excel Discussion (Misc queries) 3 August 9th 05 01:13 PM
Copy file from drive to webserver Anders[_3_] Excel Programming 0 September 18th 03 08:53 AM


All times are GMT +1. The time now is 10:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"