从Excel工作表中的列表中的VBA movefile

时间:2016-05-30 11:18:49

标签: excel vba excel-vba

我想将文件从Excel文件(listfiles.xlsx)移动到另一个文件夹,该文件包含A栏中的文件路径。下面的代码对我不起作用,你能帮帮我吗?

Sub movefile1()
Dim fso As FileSystemObject
Dim i As Long
Dim worksh As Worksheet
Dim workboo As Workbook

Set fso = CreateObject("scripting.filesystemobject")
Destination = "C:\Users\Desktop\Folder"

Set workboo = Workbooks.Open("C:\Users\TOSHIBA\Desktop\list_files.xlsx")
Set worksh = Worksheets("Listing")

numRows = worksh.Range("A" & Rows.Count).End(xlUp).Row
workboo.Windows(1).Visible = False

        For i = 2 To numRows
        Filepath = worksh.Range("A" & i).Value
        fso.CopyFile Filepath, Destination
    Next

    End Sub

我更改了代码,但fso.CopyFile Filepath, Destination不起作用。他们说许可被拒绝

1 个答案:

答案 0 :(得分:0)

将行numRows = .Range("A" & .Rows.Count).End(xlUp).Row放在循环之前,否则循环将不会执行