使用VBA删除文件时出现问题 [英] Problem deleting a file using VBA

查看:358
本文介绍了使用VBA删除文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我如何使用excel VBA保存文件的代码.

Below is the code how i save a file using excel VBA.

ActiveWorkbook.SaveAs Filename:="C:\Temp\Test.xlsx", FileFormat:=xlNormal, _
   Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
   CreateBackup:=False


在此之后,我将调用一个将压缩并保存到数据库的库.一旦将其保存在数据库中,我需要删除上述原始文件.但是,当我尝试删除它时,权限被拒绝.即使关闭了Excel应用程序,我也无法手动删除文件.

以下是用于删除文件的代码.


After this i will call a library which will zip and save to database. Once it is saved in database i need to delete the above original file. But when i try to delete it says permission denied. Even i am not able to delete the file manually, once i close the excel application i''m able to delete the file.

Below is the code used to delete the file.

Dim ObjFs As New Scripting.FileSystemObject
Dim fsofil As File
Set fsofil = ObjFs.GetFile"C:\Temp\Test.xlsx")
fsofil.Delete



在此先感谢



Thanks in advance

推荐答案

您需要先关闭文件,然后再删除它.
除非关闭文件,否则删除脚本无法正常工作.
You need to close the file before deleting it.
There is no way way the delete script will work unless the file has been closed.


这篇关于使用VBA删除文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆