下面的语句运行后,可以选择你要打开的工作簿,然后要如何处理可在最下面i2的循环嵌套里处理。
Sub data()
FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls", , "Please select the files...", , True)
If IsArray(FileToOpen) = 0 Then
'MsgBox "没有选择文件"
MsgBox "No files are selected!"
WS1.Unprotect
GoTo ErrorHandler
End If
For i2 = 1 To UBound(FileToOpen)
userfilename = FileToOpen(i2)
.....
......
.....
next i2
ErrorHandler:
end sub
VBA使用DIR函数来编列文件夹,你在VBA里面输入DIR按F1,系统会详细解释,并有例子代码。