Wednesday, September 3, 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

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog