|
Sub 宏1()
Dim sht As Worksheet
For i = 2023 To 2024
For j = 1 To 12
Set sht = Sheets.Add(After:=Sheets(Sheets.Count))
sht.Name = i & Format(j, "00")
sht.Select
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
"ODBC;DSN=Excel Files;DBQ=" & ThisWorkbook.FullName & ";DefaultDir=C:\Users\Administrator\" _
), Array( _
"Desktop\按要求拆分汇总工作表生成新的工作表;DriverId=1046;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=Range("$A$1")).QueryTable
.CommandText = "SELECT 个人编号,性别,档案出生日期,个人身份,退休类别,法定退休年龄,应退年度,应退月份 FROM [计算$] where 应退年度=" & i & " and 应退月份=" & j
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "表_" & i & Format(j, "00")
.Refresh BackgroundQuery:=False
End With
Next j
Next i
End Sub |
|