• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 105
  • Last Modified:

Excel VBA FileCopy Permission Denied - Need a way to still copy the file

In Excel VBA I use the FileCopy statement to copy a file to another location.  However, how do I accomplish FileCopy if someone has the file open ?  My current FileCopy statement results in Permission Denied Error 70 if someone has the file open.

However, I noticed if the File is Open and I go to Windows explorer and I copy the file and then paste the file in any location I do not have any issue.

How can I accomplish FileCopy even if someone has the file open ?
0
upobDaPlaya
Asked:
upobDaPlaya
  • 2
  • 2
1 Solution
 
Wayne Taylor (webtubbs)Commented:
Use FileSystemObject instead...

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile "C:\folderpath\filename.txt", "C:\newfolderpath\"

Open in new window

0
 
upobDaPlayaAuthor Commented:
Awesome !  But why does your solution work and file copy does not work if file open.
0
 
Wayne Taylor (webtubbs)Commented:
The FileCopy VBA statement is available as a simple method to copy a file. It uses a different method in the background from fso.CopyFile.
0
 
upobDaPlayaAuthor Commented:
Thank you Wayne !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now