Click here to Skip to main content
15,891,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is the code how i save a file using excel VBA.
VB
ActiveWorkbook.SaveAs Filename:="C:\Temp\Test.xlsx", FileFormat:=xlNormal, _
   Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
   CreateBackup:=False

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.
VB
Dim ObjFs As New Scripting.FileSystemObject
Dim fsofil As File
Set fsofil = ObjFs.GetFile"C:\Temp\Test.xlsx")
fsofil.Delete


Thanks in advance
Posted
Updated 26-May-11 19:47pm
v2

1 solution

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.
 
Share this answer
 
Comments
kishan NM 27-May-11 1:29am    
U meant to say the Excel application which generates the file or The process which generates the file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900