Delete a file...


Posted by Mark Gravelle on November 16, 2001 12:15 PM

I'm at the final stage of my program and cant figure out this last step.

I have 2 directories "Pending" & "Billed". The macro opens the file directory listing for "pending" and waits for the user to select a file. The rest of the macro will take this file, work with it,and "SaveAs" to the "Billed" directory.

Question: I want to "kill" the original file that was selected in the "Pending" directory. But I don't know what file they will select, as the file was originally saved as (ThisFile=Range("H3").value...etc.) and the file is retrieved by ( FileToOpen=Application_[...].GetOpenFilename[...]Workbooks.Open Filename:=FileToOpen). Do you know how I can do this? Or maybe a rename command? But I can't rename an open file.

Posted by Dank on November 16, 2001 12:36 PM

Sub TryThis()
Dim strPending As String

strPending = Application.GetOpenFilename("Microsoft Excel Files,*.xls", , "Open Pending File")

If strPending = "FALSE" Then Exit Sub 'User pressed Cancel

Workbooks.Open strPending

'Do your other stuff

ActiveWorkbook.SaveAs "C:\temp\billed\filename.xls"

Kill strPending

End Sub

Regards,
Daniel.

Posted by Dank on November 16, 2001 12:38 PM

Change FALSE to False for the cancel part to work.....



Posted by Thanks, Daniel. I'll give it a shot. on November 16, 2001 12:47 PM

Re: Change FALSE to False for the cancel part to work.....