将单元格内容识别为文件名的语法

我已经写了一个Excelmacros将PDF文件从源文件夹复制到目标文件夹。 我现在正试图将一个Do循环合并到macros中,这样我就可以移动多个文件,每个文件都在一个单独的单元中标识。 此外,要移动的文件数量也会有所不同。

当我使用命令行

sFile = Range("G14").Value & ".pdf" 

它会将单元格G14中列出的文件复制到目标文件夹。 但是,我没有使用Do LoopsFiles = Cells (I,7)来增加我想要移动的一系列文件名。 这个macros在最后一步轰炸。

任何build议,将不胜感激。

 Sub Copying_File() Sheets("Sheet1").Select I = 8 Do I = I + 1 If Cells(I, 7) = "zzzz" Then Cells(I, 8) = "Transfer of Files Complete" If Cells(I, 7) = "zzzz" Then Exit Do 'Declare Variables Dim FSO Dim sFile As String Dim sSFolder As String Dim sDFolder As String 'This is Your File Name which you want to Copy sFile = Cells(I, 7).Value & ".pdf" 'Change to match the source folder path sSFolder = "I:\PatschB\ZZZ Source\" 'Change to match the destination folder path sDFolder = "I:\PatschB\ZZZ Destination\" 'Create Object Set FSO = CreateObject("Scripting.FileSystemObject") 'Copying File to Destination Folder FSO.CopyFile (sSFolder & sFile), sDFolder Loop End Sub 

CopyFile需要两个完整path – 都应该包含文件名

尝试replace这一行:

 FSO.CopyFile (sSFolder & sFile), sDFolder 

用这一行:

 FSO.CopyFile sSFolder & sFile, sDFolder