Sub GetFileList()
Dim varFileList As Variant
Dim FSO As Object, myFile As Object
Dim l As Long
Dim f As String
Dim i As Integer
'显示打开文件夹对话框
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
If .SelectedItems.Count = 0 Then Exit Sub '未选择文件夹
strFolder = .SelectedItems(1)
End With
'获取文件夹中的所有文件列表
i = 0
f = Dir$(strFolder & "\*.*")
Do While Len(f) > 0
Cells(i + 2, 2) = f
i = i + 1
f = Dir$()
Loop
End Sub
Private Sub CommandButton2_Click()
GetFileList
End Sub
Private Sub CommandButton1_Click()
Dim i As Integer
Dim n As Integer
Dim SPath As String
SPath = strFolder + "\"
n = [a65536].End(xlUp).Row
For i = 2 To n
If Dir(SPath + (Cells(i, 2).Value)) = "" Then
Cells(i, 3).Value = "原文件不存在!"
Else
Name SPath + (Cells(i, 2).Value) As SPath + (Cells(i, 1).Value)
Cells(i, 3).Value = "OK!"
End If
Next