Solved

VB6 - FileCopy problem.

Posted on 2003-10-27
10
2,795 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

734 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