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 ?
upobDaPlayaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.