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?
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?
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
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks