如何使vba文件自行删除

时间:2015-12-17 21:53:56

标签: windows vba batch-file cmd

我正在尝试删除程序,我正在使用单独的批处理文件来执行此操作。我正在使用此代码:

Process.Start("cmd.exe", 
    "/C choice /C Y /N /D Y /T 1 & Del " + Application.ExecutablePath)
Application.Exit()

但它无法删除名称中带有空格的文件。如何将Application.ExecutablePath与“”包围在一起,使其最终看起来像“FileName”?

1 个答案:

答案 0 :(得分:2)

我弄清楚了,我使用了这段代码:

Dim applicationPath As String
Dim quote As String
quote = Chr(34)
applicationPath = fso.GetFileName(Application.ExecutablePath)
Process.Start("cmd.exe",
    "/C choice /C Y /N /D Y /T 1 & Del " + quote & applicationPath & quote)
Application.Exit()

解决问题有很多额外的代码。所以我把它简化为:

Dim quote As String
quote = Chr(34)
Process.Start("cmd.exe",
    "/C choice /C Y /N /D Y /T 1 & Del " + quote & Application.ExecutablePath & quote)
Application.Exit()