excel vba如何打开 关闭多个工作薄

时间:2016-09-16 06:22:32 

用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

看不过瘾?点击下面链接!
本站微信公众号:gsjx365,天天有好故事感动你!

相关电脑知识

美图欣赏

电脑知识排行榜