Delete files from an Excel macro

matthewh

New Member
Joined
Mar 13, 2002
Messages
34
I have to pull a set of scanned invoice images monthly from a UNIX database, and burn them onto CD. There are usually several hundred. Now I have to filter certain ones out by company, but the software we have to do this won't do it the way I need to. What I want to do is generate a list of images that I DON'T want by Excel querying the database via our ODBC link, then pulling off the this month's images and deleteing the unwanted ones that are on the above list.

I want to put it into a macro so I can run it easily, but can I delete, say, image (tif) files from an Excel macro?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
Hello,

You can do this using the charmingly named Kill statement e.g.

Kill "C:tempimage.tif"

You could obviously set up a loop to run through your query and delete each file.
 

matthewh

New Member
Joined
Mar 13, 2002
Messages
34
Thanks Dan, never used it but it should save me several hours!

On 2002-09-11 01:15, dk wrote:
Hello,

You can do this using the charmingly named Kill statement e.g.

Kill "C:tempimage.tif"

You could obviously set up a loop to run through your query and delete each file.
 

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,456
Hi matthewh,
If you need to delete a lot of tif files, please try this loop. :)

<pre>
Sub EG()
Const strMsg As String = "Prease select folder"
Dim strPath As String, strTemp As String
Dim objFolder As Object, lngRet As Long

Set objFolder = CreateObject("Shell.Application"). _
BrowseForFolder(0, strMsg, &H1)
If Not objFolder Is Nothing Then
strPath = objFolder.self.Path & ""
Else
MsgBox strMsg, vbCritical
Exit Sub
End If

lngRet = MsgBox("Do you want to kill all the tif files in" & _
vbLf & strPath, 36)
If lngRet <> vbYes Then Exit Sub
strTemp = Dir(PathName:=strPath & "*.TIF")
Do While strTemp <> ""
Kill strPath & strTemp
strTemp = Dir
Loop
End Sub
</pre>
 

Forum statistics

Threads
1,144,766
Messages
5,726,173
Members
422,659
Latest member
RGP268

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top