Solved

VB6 - FileCopy problem.

Posted on 2003-10-27
10
2,690 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
  • 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
 
LVL 2

Accepted Solution

by:
wuttrain earned 50 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:daleyjem
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now