Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send File to Recycle Bin 1

Status
Not open for further replies.

SeaRay

Technical User
Jan 8, 2002
20
US
What is the vba code to send a file to the recycle bin?
 
Straight from API-guide ver. 3.6.630 (
Code:
'This program needs a Common Dialog Box, named CDBox.
'  (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
'   and select Microsoft Common Dialog control)
Private Type SHFILEOPSTRUCT
    hWnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAborted As Boolean
    hNameMaps As Long
    sProgress As String
End Type
Private Const FO_DELETE = &H3
Private Const FOF_ALLOWUNDO = &H40
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Private Sub Form_Load()
    'KPD-Team 1998
    'URL: [URL unfurl="true"]http://www.allapi.net/[/URL]
    'E-Mail: KPDTeam@Allapi.net
    Dim SHFileOp As SHFILEOPSTRUCT
    'Set the dialog's title
    CDBox.DialogTitle = "Select a file to delete ..."
    'Set the dialog's filter
    CDBox.Filter = "All Files (*.*)|*.*"
    'Show the 'Open File' dialog
    CDBox.ShowOpen
    With SHFileOp
        'Delete the file
        .wFunc = FO_DELETE
        'Select the file
        .pFrom = CDBox.filename
        'Allow 'move to recycle bn'
        .fFlags = FOF_ALLOWUNDO
    End With
    'perform file operation
    SHFileOperation SHFileOp
    MsgBox "The file '" + CDBox.filename + "' has been moved to your Recycling Bin !", vbInformation + vbOKOnly, App.Title
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top