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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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.
 
Upvote 0
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.
 
Upvote 0
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>
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,704
Members
449,048
Latest member
81jamesacct

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
Back
Top