如何在VB6中复制打开的文件?

时间:2009-07-15 07:41:00

标签: vb6

使用VB6,当另一个人打开文件时,如何将文件从另一台计算机复制到我的电脑?

2 个答案:

答案 0 :(得分:8)

如果尝试在当前打开的文件上使用FileCopy语句,则会发生错误。但是,FileSystemObject的CopyFile函数没有问题,所以请改用它。首先,您需要添加对Microsoft Scripting Runtime的引用(在Project-> References ...菜单上)。然后你可以这样做:

Dim fso As New FileSystemObject

fso.CopyFile "\\someOtherComputer\share\foo.mdb", "C:\foo.mdb"

答案 1 :(得分:3)

您也可以使用Windows API

Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long



Public Function CopyFileA(OldFileName As String, NewFileName As String) As Boolean
    On Error Resume Next

    If CopyFile(OldFileName, NewFileName, False) <> 1 Then
        MsgBox "Error copying file", vbExclamation, 
    Else
        CopyFileA = True
    End If
End Function