我有这段代码,我的目标是从当前模板文件夹复制并粘贴一个文件夹(及其所有内容),以粘贴到基于字段值的目标文件路径上,作为新文件目标名称的条件。
我收到一个错误:
FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
不知道为什么,请您帮忙。谢谢你。
Private Sub Command83_Click()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
FromPath = "C:\Database Test Center\Master" '<< Change
ToPath = "C:\Database Test Center\Projects\" & Me.ProjectName.Value & "-" &
Me.Lead.Value & "\MasterTemplate"
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath
End Sub