+ Reply to Thread
Results 1 to 3 of 3

Bin File using VBA

  1. #1
    dl
    Guest

    Bin File using VBA

    To delete a file from the file sytem you use the VBA command

    Kill

    Is there a way to rather delete and send the file to the bin/trash can on
    the computer using VBA?



  2. #2
    Dave Peterson
    Guest

    Re: Bin File using VBA

    Chip Pearson posted this:

    You have to do it via a Windows API call -- there is no built-in VBA way to
    do it.

    '----------------------------------------------
    Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Boolean
    hNameMappings As Long
    lpszProgressTitle As String
    End Type
    Private Const FO_DELETE = &H3
    Private Const FOF_ALLOWUNDO = &H40

    Declare Function SHFileOperation Lib "shell32.dll" Alias _
    "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long


    Sub RecycleFile(FileName As String)
    Dim lReturn As Long
    Dim sFileName As String
    Dim FileOperation As SHFILEOPSTRUCT

    With FileOperation
    .wFunc = FO_DELETE
    .pFrom = FileName
    .fFlags = FOF_ALLOWUNDO
    End With

    lReturn = SHFileOperation(FileOperation)

    End Sub
    '----------------------------------------------

    Then call this with

    RecycleFile FileName:="G:\Temp\Book1.xls"




    dl wrote:
    >
    > To delete a file from the file sytem you use the VBA command
    >
    > Kill
    >
    > Is there a way to rather delete and send the file to the bin/trash can on
    > the computer using VBA?


    --

    Dave Peterson

  3. #3
    dl
    Guest

    Re: Bin File using VBA

    Thanks Dave

    "Dave Peterson" <petersod@verizonXSPAM.net> wrote in message
    news:4326B7D2.F3E303CD@verizonXSPAM.net...
    > Chip Pearson posted this:
    >
    > You have to do it via a Windows API call -- there is no built-in VBA way
    > to
    > do it.
    >
    > '----------------------------------------------
    > Type SHFILEOPSTRUCT
    > hwnd As Long
    > wFunc As Long
    > pFrom As String
    > pTo As String
    > fFlags As Integer
    > fAnyOperationsAborted As Boolean
    > hNameMappings As Long
    > lpszProgressTitle As String
    > End Type
    > Private Const FO_DELETE = &H3
    > Private Const FOF_ALLOWUNDO = &H40
    >
    > Declare Function SHFileOperation Lib "shell32.dll" Alias _
    > "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    >
    >
    > Sub RecycleFile(FileName As String)
    > Dim lReturn As Long
    > Dim sFileName As String
    > Dim FileOperation As SHFILEOPSTRUCT
    >
    > With FileOperation
    > .wFunc = FO_DELETE
    > .pFrom = FileName
    > .fFlags = FOF_ALLOWUNDO
    > End With
    >
    > lReturn = SHFileOperation(FileOperation)
    >
    > End Sub
    > '----------------------------------------------
    >
    > Then call this with
    >
    > RecycleFile FileName:="G:\Temp\Book1.xls"
    >
    >
    >
    >
    > dl wrote:
    >>
    >> To delete a file from the file sytem you use the VBA command
    >>
    >> Kill
    >>
    >> Is there a way to rather delete and send the file to the bin/trash can on
    >> the computer using VBA?

    >
    > --
    >
    > Dave Peterson




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1