目录
示例
如图所示,在同一个目录下有多个工作表名称相同的工资汇总月报。现希望通过VBA建立该多个月份的月报总表,将多个工作簿中的“工资汇总”工作表导入当前工作簿,并以月份命名。该如何实现呢?
实现代码
Option Explicit
Sub 批量导入工作表()
Dim FileName As String
Dim FilePath As String
Dim wbkThis As Workbook
Dim wbkOpen As Workbook
Dim shtNew As Worksheet
Dim shtData As Worksheet
'禁止屏幕刷新
Application.ScreenUpdating = False
'设置当前工作薄
Set wbkThis = ThisWorkbook
'关闭警告
Application.DisplayAlerts = False
'删除当前工作薄中除Sheet1外的所有工作表
For Each shtNew In wbkThis.Worksheets
If shtNew.Name <> Sheet1.Name Then
shtNew.Delete
End If
Next
'打开警告
Application.DisplayAlerts = True
'获取当前工作薄路径
FilePath &