nnsea 发表于 2023-1-13 22:29:29

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



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
页: [1]
查看完整版本: 删除指定目录中的指定文件vba