搜索
查看: 441|回复: 0

删除指定目录中的指定文件vba

[复制链接]

977

主题

1093

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
15931
发表于 2023-1-13 22:29:29 | 显示全部楼层 |阅读模式


Sub 删除文件()
    Dim myFile As String
    myFile = ThisWorkbook.Path & "\VBA基实很简单.xlsm"
    On Error Resume Next
    Kill myFile
    On Error GoTo 0
End Sub


Sub 删除文件()
    Dim myFile As String
    Dim myNewFilePath As String
    Dim fso As Scripting.FileSystemObject
    myFile = ThisWorkbook.Path & "\VBA基实很简单.xlsm"    '要删除的文件
    Set fso = New Scripting.FileSystemObject
    If fso.FileExists(myFile) Then
        fso.DeleteFile myFile
        MsgBox "已经将文件 " & myFile & " 删除"
    Else
        MsgBox "要删除的文件不存在"
    End If
    Set fso = Nothing
End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

表格智创网

网站简介:表格智创网,是一家以表格设计和技能分享的专业社区,由会计帮帮网投资建设,尽专业,助提高专业技能。

表格智创网欢迎您!

联系我们

  • 工作时间:早上9:00-16:00
  • 客服电话:18668755857
  • 本站网址:www.excelwps.com
  • 淘宝店址:kjbbw.taobao.com

Powered by Discuz! X3.4 © 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表