Wednesday, 3 September 2014

How to Delete a Specific File from a Folder using Excel VBA Macro

Excel VBA Macro to Delete a Specific File from a Folder
Sub Delete_File()
Dim FSO as Object
Dim sFile As String

'Source File Location
sFile = "C:\Users\Tamatam\Desktop\Temp\Test.jpg" 'You can change this Loaction

'Set Object
Set FSO = CreateObject("Scripting.FileSystemObject")

'Check File Exists or Not
If FSO.FileExists(sFile) Then

'If file exists, It will delete the file from source location
FSO.DeleteFile sFile, True
MsgBox "Deleted The File Successfully", vbInformation, "Done!"
Else

'If file does not exists, It will display following message
MsgBox "Specified File Not Found", vbInformation, "Not Found!"
End If
End Sub

Thanks,
TAMATAM

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts