删除当前文件并保留我保存的csv

时间:2014-12-08 13:11:22

标签: excel vba excel-vba

我正在尝试删除当前打开的excel文件。我没有特定的名称,所以必须这样 Kill .FullName

当我这样做时:

    Dim relativePath As String
relativePath = "\\FILES\" & Format(Now, "yyyy-mm-dd hh_mm") & " - " & ActiveWorkbook.Name
ActiveWorkbook.SaveAs Filename:=relativePath


Application.DisplayAlerts = False
 ActiveWorkbook.SaveAs Filename:= _
"C:\PROGRAM.csv", FileFormat:=xlCSV _
, CreateBackup:=False, Local:=True


On Error Resume Next
With ActiveWorkbook
.Saved = True
.ChangeFileAccess xlReadOnly
Kill .FullName
.Close False
End With
On Error GoTo 0

Application.DisplayAlerts = True

它不会仅删除保存的PROGRAM.csv我的初始文件 任何人都可以帮我删除我最初打开的文件吗?

1 个答案:

答案 0 :(得分:0)

首次SaveAs之前,在originalName = ActiveWorkbook.FullName原始文件之后的任何地方添加一行SaveAs然后再向下,添加Kill originalName