?
Solved

VB6 - FileCopy problem.

Posted on 2003-10-27
10
Medium Priority
?
2,860 Views
Last Modified: 2010-08-05
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
Comment
Question by:2Angel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 9627032
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
 
LVL 2

Author Comment

by:2Angel
ID: 9627074
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
 
LVL 2

Author Comment

by:2Angel
ID: 9627081
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!

 
LVL 2

Accepted Solution

by:
wuttrain earned 200 total points
ID: 9627189
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
 
LVL 4

Expert Comment

by:Jeremy Daley
ID: 9628475
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
 
LVL 2

Expert Comment

by:wuttrain
ID: 9631356
did you test the API code I suggested?
0
 

Expert Comment

by:Hyperon
ID: 9632689
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
 
LVL 4

Expert Comment

by:Jeremy Daley
ID: 9633368
yeah, i think hyperon has a point there...i'd try that
0
 

Expert Comment

by:Hyperon
ID: 9633514
i just prefer dos lol

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

try that code i suggested, it should work
0
 
LVL 2

Author Comment

by:2Angel
ID: 9633949
wuttrain: It's working very gggggoooooooddddddd

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


Angel
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question