Re: Excel VBA to move file to recycle bin
Is there a 64 Bit version? or maybe a different way in VBA?
Code
Private Type SHFILEOPTSTRUCT hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type
Private Declare Function SHFileOperation Lib "Shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPTSTRUCT) As Long
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10
Public Sub DeleteFile(Filename As String, _
Optional Recycle As Boolean = True, _
Optional NoPrompt As Boolean = False)
Dim fop As SHFILEOPTSTRUCT
Dim Flags As Integer
On Error Goto Catch
With fop
.wFunc = FO_DELETE
.pFrom = Filename
.fFlags = IIf(Recycle, FOF_ALLOWUNDO, 0) + IIf(NoPrompt, FOF_NOCONFIRMATION, 0)
End With
If SHFileOperation(fop) <> 0 Then Err.Raise 30001, "Deletefile", "Unable to " IIf(recycle, "recycle ", "delete ") " & UCase(Filename)
Exit Sub
Catch:
MsgBox "ERROR: " & Err.Description, vbExclamation, "DeleteFile"
End Sub
Display More
Code
Private Declare Function SHFileOperation Lib "Shell32.dll" _
Alias "SHFileOperationA" (lpFileOp As SHFILEOPTSTRUCT) As Long
And
Code
If SHFileOperation(fop) <> 0 Then Err.Raise 30001, "Deletefile", "Unable to " IIf(recycle, "recycle ", "delete ") " & UCase(Filename)
Are in red
Thanks