VB6 - FileCopy problem.


I am using filecopy(path,filenam).... to copy MsWord document.

But when the file is open I get error msg.

Any help?

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

the file is open so it's a problem to overwrite it you can try 2 things

handle the error in a on error trap

on error goto errhandler

....your code

  exit sub
  if err.number = xxx then
    'check if this is the copy error
    'another error
  end if
  exit sub

or use the word vba method where you can use the saveascopy method and application.displayalerts to hide the warnings on overwriting but i think you get the same error here on trying to overwrite an open file
2AngelAuthor Commented:
I alredy use errhandler....

I don't want to overwrite the file I want to copy it to diferent folder whil it's open.
2AngelAuthor Commented:
bytheway, its posible to do so (whil the file is open) siply by using Windows Explorer...
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

try this:

Option Explicit
Private Declare Function CopyFile Lib "kernel32" _
   Alias "CopyFileA" _
  (ByVal lpExistingFileName As String, _
   ByVal lpNewFileName As String, _
   ByVal bFailIfExists As Long) As Long

Private Sub Command1_Click()

   CopyFile "c:\f.doc", "c:\fback.doc", False

End Sub

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
Jeremy DaleySenior DeveloperCommented:
can't you just temporarily close the file, then copy it, and open it again?

i'd do something like:

   dim fso as new filesystemobject
' do this loop to make sure the file gets copied before you try to reopen the file
   do until fso.fileexists("c:\thefile")=true

did you test the API code I suggested?
use dos to do it for you: shell "command.com copy " & filename$ & " " 7 filedest$

where filename$ and filedest$ are the appropriate strings of the filename and the destination
Jeremy DaleySenior DeveloperCommented:
yeah, i think hyperon has a point there...i'd try that
i just prefer dos lol

(and linux, but we won't get onto that, :D)

try that code i suggested, it should work
2AngelAuthor Commented:
wuttrain: It's working very gggggoooooooddddddd

Thank you very much for the help........

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
Visual Basic Classic

From novice to tech pro — start learning today.