将文件从一个目标文件夹复制到另一个

我目前正在尝试复制文件从一个文件夹到另一个指定的文件夹使用Excel VBAmacros,我的数据是在Excel的工作表1,我已经设置我的文件名在单元格B5,源文件夹在B6上目标文件夹位于单元格B7上。 这是我的代码如下:

'In this Example I am Copying the File From one loaction to another location 'as per the details specified in the Worksheet. Sub sbCopyingAFileReadFromSheet() 'Declaration Dim FSO Dim sFile As String Dim sSFolder As String Dim sDFolder As String sFile = Sheets("Sheet1").Range("B5") sSFolder = Sheets("Sheet1").Range("B6") sDFolder = Sheets("Sheet1").Range("B7") Set FSO = CreateObject("Scripting.FileSystemObject") If Not FSO.FileExists(sSFolder & sFile) Then MsgBox "Specified File Not Found in Source Folder", vbInformation, "Not Found" ElseIf Not FSO.FileExists(sDFolder & sFile) Then FSO.CopyFile (sSFolder & sFile), sDFolder, True MsgBox "Specified File Copied to Destination Folder Successfully", vbInformation, "Done!" Else MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists" End If End Sub 

但是即使该文件在源文件夹中,“在源文件夹中找不到指定的文件”错误消息仍会popup。 请协助

当使用sSFolder & sFile确保两个variables之间有一个“\”,就像这样

 sSFolder & "\" & sFile 

使用path分隔符:

 If Not FSO.FileExists(sSFolder & Application.PathSeparator & sFile) Then