VB6 - FileCopy problem.

Hi,

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

But when the file is open I get error msg.

Any help?


Tks,
Angel
LVL 2
2AngelAsked:
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.

bruintjeCommented:
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
errhandler:
  if err.number = xxx then
    'check if this is the copy error
  else
    '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
0
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.
0
2AngelAuthor Commented:
bytheway, its posible to do so (whil the file is open) siply by using Windows Explorer...
0
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.

wuttrainCommented:
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
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
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
   loop

0
wuttrainCommented:
did you test the API code I suggested?
0
HyperonCommented:
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
0
Jeremy DaleySenior DeveloperCommented:
yeah, i think hyperon has a point there...i'd try that
0
HyperonCommented:
i just prefer dos lol

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

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

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


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

From novice to tech pro — start learning today.

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.