Option
Explicit
Private
Declare
Function
CopyFile
Lib
"kernel32"
_
Alias
"CopyFileA"
(
ByVal
lpExistingFileName
As
String
, _
ByVal
lpNewFileName
As
String
,
ByVal
bFailIfExists
As
Long
) _
As
Long
Sub
APICopy()
Dim
cflag
As
Boolean
Dim
sfile
As
String
Dim
tfile
As
String
sfile =
"E:\VBA\Source\Mappe2.pdf"
tfile =
"E:\VBA\Target\Mappe4.pdf"
Call
fCopy(sfile, tfile)
End
Sub
Public
Function
fCopy(ssource
As
String
, starget
As
String
, _
Optional
IfExist
As
Boolean
)
As
Boolean
Dim
lflag
As
Long
lflag = CopyFile(ssource, starget, IfExist)
fCopy = (lflag > 0)
End
Function
Sub
fsoCopy()
Dim
sfile
As
String
Dim
tfile
As
String
Dim
ofso
As
Object
sfile =
"E:\VBA\Source\Mappe2.pdf"
tfile =
"E:\VBA\Target\Mappe5.pdf"
Set
ofso = CreateObject(
"Scripting.FileSystemObject"
)
ofso.CopyFile sfile, tfile
Set
ofso =
Nothing
End
Sub
Sub
VBAcopy()
Dim
sfile
As
String
Dim
tfile
As
String
Dim
ofso
As
Object
sfile =
"E:\VBA\Source\Mappe2.pdf"
tfile =
"E:\VBA\Target\Mappe5.pdf"
FileCopy sfile, tfile
End
Sub