删除文件而不指定路径

时间:2017-08-07 19:27:27

标签: excel excel-vba vba

我想重命名一个文件,然后删除同一文件路径中的旧文件。

我想删除必须指定路径的旧文件whitout。

Private Sub CommandButton4_Click()

    Dim src As String, dst As String, fl As String
    Dim rfl As String

    'Source directory
   src = ActiveWorkbook.Path

    'Destination directory
    dst = ActiveWorkbook.Path

    'File name
    fl = "file.mdb"

    'Rename file
    rfl = "file_OLD.mdb"

    On Error Resume Next
        FileCopy src & "\" & fl, dst & "\" & rfl
        If Err.Number <> 0 Then
            MsgBox "Copy error: " & src & "\" & rfl
        End If
    On Error GoTo 0

   Kill file


End Sub

1 个答案:

答案 0 :(得分:1)

你可以使用 Name src & "\" & fl As dst & "\" & rfl