这应该很容易但我甚至无法编译。我使用了“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)
非常感谢任何帮助。
答案 0 :(得分: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
HERE
如果它死了,请从链接中引用。
修改强>
解决您的问题
如果您是早期绑定,请将引用设置为Tools | Reference | Microsoft Scripting Runtime
。 Dim 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