Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3055
  • Last Modified:

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
0
2Angel
Asked:
2Angel
  • 3
  • 2
  • 2
  • +2
1 Solution
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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