Kill宏返回53错误

时间:2016-01-07 15:07:39

标签: excel-vba vba excel

此宏返回53错误。

如果我使用带有Kill命令的CSVPath2变量,宏可以工作,但是如果我使用sProcessFile变量则不行。

Sub DELETE()
Dim CSVPath As String
Dim CSVPath2 As String
Dim sProcessFile As String

CSVPath = "c:\TEST\"
'CSVPath2 = "c:\TEST\*.csv"
sProcessFile = Dir(CSVPath & "*.csv")

Kill sProcessFile

End Sub

1 个答案:

答案 0 :(得分:1)

您需要完整的文件规范(包括路径)

在我的机器上:

Sub DELETE()
   Dim CSVPath As String
   Dim sProcessFile As String

   CSVPath = "C:\TestFolder\"
   sProcessFile = Dir(CSVPath & "*.csv")
   Kill CSVPath & sProcessFile
End Sub