首页 > 解决方案 > 在 VBA 中合并文件夹并跳过错误

问题描述

我正在合并两个文件夹,但可能需要创建新的子文件夹,因此我需要查看是否存在子文件夹,如果不创建新文件夹,请移动文件夹中的文件,如果文件不存在则跳过错误正在检查的列表。这是源的 excel 表这是输出

Sub MoveFiles()
fileLocation = "/Users/wynandgoosen/Downloads/SULL/Drive/About/" 'change to the top level parent folder

Range("A2").Select

'loop through all records in the list
'identifieswhich have been marked as archive
'move the marked files to the ARCHIVE folder

Do While ActiveCell.Value <> ""
    If ActiveCell.Offset(0, 3).Value = "Move" Then
        Name ActiveCell.Offset(0, 2).Value & "/" & ActiveCell.Offset(0, 1).Value As _
        fileLocation & ActiveCell.Value & "/" & ActiveCell.Offset(0, 1).Value

On Error Resume Next

ActiveCell.Offset(0, 2).Value = fileLocation
ActiveCell.Offset(0, 3).Value = "YES"

End If

ActiveCell.Offset(1, 0).Select
Loop

End Sub

标签: vbaerror-handlingmerge

解决方案


推荐阅读