Private Declare PtrSafe Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Long
Private Type SHFILEOPSTRUCT
hwnd As LongPtr
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As LongPtr
lpszProgressTitle As String
End Type
Private Const FO_DELETE As Long = &H3
Private Const FOF_ALLOWUNDO As Integer = &H40
Private Const FOF_NOCONFIRMATION As Integer = &H10
Sub MoveToRecycleBin()
'https://www.mrexcel.com/board/threads/sending-file-to-recycle-bin.1265231/
Dim fileOp As SHFILEOPSTRUCT
Dim MyFile As String
MyFile = "C:\Users\username\Downloads\Macros.xlsx" & vbNullChar '
With fileOp
.wFunc = FO_DELETE
.pFrom = MyFile
.fFlags = FOF_ALLOWUNDO Or FOF_NOCONFIRMATION
End With
SHFileOperation fileOp
End Sub