ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > E问E答 > Excel VBA > 如何将文件删除至回收站,并清空回收站

如何将文件删除至回收站,并清空回收站

作者:绿色风 分类: 时间:2022-08-17 浏览:88
楼主
xmyjk
Q:如何将文件删除至回收站,并清空回收站。

A:API操作之。
  1. Option Explicit

  2. Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As ToBin) As Long
  3. Private Declare Function SHEmptyRecycleBin Lib "shell32.dll" Alias "SHEmptyRecycleBinA" (ByVal hwnd As Long, ByVal pszRootPath As String, ByVal dwFlags As Long) As Long

  4. Private Type ToBin
  5.     hwnd As Long
  6.     wFunc As Long
  7.     pFrom As String
  8.     pTo As String
  9.     fFlags As Integer
  10.     fAnyOperationsAborted As Long
  11.     hNameMappings As Long
  12.     lpszProgressTitle As Long
  13. End Type

  14. Const FO_DELETE = &H3
  15. Const FOF_ALLOWUNDO = &H40
  16. Const SHERB_NORMAL = &H0

  17. Private Sub 删除()
  18.     Dim Go As ToBin
  19.     Dim strFile As String

  20.     strFile = ThisWorkbook.Path & "\1.TXT"

  21.     With Go
  22.         .wFunc = FO_DELETE
  23.         .pFrom = strFile
  24.         .fFlags = FOF_ALLOWUNDO
  25.     End With

  26.     SHFileOperation Go
  27. End Sub

  28. Private Sub 清空回收站()
  29.     Dim RetVal As Long
  30.     RetVal = SHEmptyRecycleBin(0&, vbNullString, SHERB_NORMAL)
  31. End Sub

删除文件.zip
2楼
yjzstar
3楼
水星钓鱼
学习
4楼
我是小马儿
感觉用kill 方便且简单一点呢。

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap