Tom’s Tutorials For Excel: Emptying the Recycle Bin

Tom’s Tutorials For Excel: Emptying the Recycle Bin

This macro with API empties the Recycle Bin.

Recycle
In a new fresh standard module:

Declare Function EmptyRecycleBin _
Lib "shell32.dll" Alias "SHEmptyRecycleBinA" _
(ByVal hwnd As Long, _
ByVal pszRootPath As String, _
ByVal dwFlags As Long) As Long

Sub RecycleBinEmpty()
Dim rbEmpty As Long
rbEmpty = EmptyRecycleBin(0&, vbNullString, 1&)
End Sub

Thanks to OnErrorGoto0 for assistance on this one.

Share Button
Posted in Tom's Tutorials for Excel
Tags: , , , , , , , , , , , ,
2 comments on “Tom’s Tutorials For Excel: Emptying the Recycle Bin
  1. Tom Bollah says:

    Hi,
    I want to insert the code above in a personal Excel development. But before to call the “EmptyRecycleBin” function, I would test if the recycle bin is empty or not.
    Is it possible? and if yes how can I test it?
    Thanks in advance for the answer.

    Tom

    • Tom Urtis says:

      My personal take on that is to first ask myself why I am checking for this or that as a condition. In this case, suppose there is nothing in your Recycle Bin. Emptying it would be instantaneous and so the act of checking beforehand to see if it’s empty would take longer than emptying what’s not there. So if it were me, I’d just run the code and not check first to see if I don’t need to run it, because the worst case scenario is that nothing needed to be emptied in the first place.

Leave a Reply

Your email address will not be published. Required fields are marked *

*