1

这应该很容易,但我什至无法编译。我使用了“regsvr32 scrrun.dll”并重新启动无济于事。这是代码:

Dim fso As Scripting.FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")

Dim destpath As String
Dim sourcepath As String
Dim filename As String

sourcepath = "\\spap097\VISIONFILES\Attachments"    
destpath = "\\spap097\VISIONFILES\Attachments\Temp Folder for 35870 Visions Files"
filename = "test.docx"

' now do the copy
fso.CopyFile(sourcepath & "\" & filename, destpath & "\" & filename)

非常感谢任何帮助。

4

1 回答 1

1

这是一个更好的选择。

你的 9 行代码可以减少到 7 行

Dim destpath As String
Dim sourcepath As String
Dim filename As String

sourcepath = "\\spap097\VISIONFILES\Attachments"
destpath = "\\spap097\VISIONFILES\Attachments\Temp Folder for 35870 Visions Files"
filename = "test.docx"

FileCopy sourcepath & "\" & filename, destpath & "\" & filename

或进一步到 5 行

Dim destpath As String, sourcepath As String, filename As String

sourcepath = "\\spap097\VISIONFILES\Attachments"
destpath = "\\spap097\VISIONFILES\Attachments\Temp Folder for 35870 Visions Files"
filename = "test.docx"

FileCopy sourcepath & "\" & filename, destpath & "\" & filename

您可能还想在FILECOPY 此处查看 MSDN 文章

如果它死了,请从链接中引用。

在此处输入图像描述

编辑

解决您的问题

如果您是早期绑定,请设置参考Tools | Reference | Microsoft Scripting RuntimeDim fso As Scripting.FileSystemObject如果你是后期绑定,Dim fso As Object那么你不需要设置参考。

行中有错误fso.CopyFile(sourcepath & "\" & filename, destpath & "\" & filename)您有括号()

Sub Sample()
    '~~> Any of the below will work.
    Dim fso As Scripting.FileSystemObject        
    'Dim fso As Object

    Set fso = CreateObject("Scripting.FileSystemObject")

    Dim destpath As String
    Dim sourcepath As String
    Dim filename As String

    sourcepath = "\\spap097\VISIONFILES\Attachments"
    destpath = "\\spap097\VISIONFILES\Attachments\Temp Folder for 35870 Visions Files"
    filename = "test.docx"

    ' now do the copy
    fso.CopyFile sourcepath & "\" & filename, destpath & "\" & filename
End Sub
于 2013-10-22T16:57:51.763 回答