用excel VBA 編寫打開和關閉多個工作薄,相應的代碼如下:
1、打開指定工作簿
dim wb as workbook
set wb = " 文件路徑及文件名"
workbooks.open filename:= wb
2、關閉所有工作簿並保存
workbooks.close
3、打開多個工作薄的程序代碼:
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