Deleting/Moving another workbook from inside a workbook


Posted by Gail on August 16, 2001 11:28 AM

Is there VBA code that will permit me to delete and/or move another workbook from one network folder to another from inside the workbook I am in (the one with the code in it - the controller!)? Thanks, G



Posted by Dax on August 16, 2001 11:45 AM

Gail,
This code might do something you're after:-

Sub MoveAndDeleteOtherWorkbook()
Dim FSObj As Object
Dim sTargetFile As String
Dim sSourceForFile As String

Set FSObj = CreateObject("Scripting.FilesystemObject")
'Demonstrates how to move a file from one location to another
sTargetFile = "C:\Temp\FantasyFooty.xls"
sSourceForFile = "C:\"

FSObj.MoveFile sTargetFile, sSourceForFile

'Now how to delete a file
sTargetFile = "C:\temp\book1.xls"

FSObj.DeleteFile sTargetFile

End Sub

I hope it helps,

Dax