下面的VBA代码先用Application.GetOpenFilename方法显示“打开”文件对话框,然后打开所选择的一个或多个Excel工作簿文件。
Sub OpenWorkbooks()
On Error Resume Next
Dim SelectFiles As Variant
‘显示打开文件对话框
SelectFiles = Application.GetOpenFilename("Excel 文件 (*.xl*)," & "*.xl*", , "打开", , True)
‘未选择
If TypeName(SelectFiles) = "Boolean" Then
Exit Sub
End If
‘打开所选工作簿
For i = 1 To UBound(SelectFiles)
Workbooks.Open SelectFiles(i)
Next i
End Sub
温馨提示:答案为网友推荐,仅供参考