VBA:RmDir pathname运行时出错:运行时错误“75”,路径或文件访问时错误。

Dim graPath As String
graPath = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name & "_graphics"
'判断目录是否存在,存在就删除目录中的所有文件及目录本身
If Dir(graPath, vbDirectory) <> "" Then
If Dir(graPath & "\*.*") <> "" Then
Kill graPath & "\*.*" '没有子目录
RmDir graPath '删除目录的时候老是出错,不知道为什么
End If
End If

'原因是Kill过程文件还没有完全删除时,已经开始执行RmDir,所以出错。
'修改如下:
Dim graPath As String
graPath = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name & "_graphics"
'判断目录是否存在,存在就删除目录中的所有文件及目录本身
If Dir(graPath, vbDirectory) <> "" Then
If Dir(graPath & "\*.*") <> "" Then
Kill graPath & "\*.*" '没有子目录
End If
End If
If Dir(graPath, vbDirectory) <> "" Then
If Dir(graPath & "\*.*") = "" Then
RmDir graPath '文件删除完成后,再删除文件夹
End If
End If
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网