简易VBA代码

2022-05-19 23:42:12   文档大全网     [ 字体: ] [ 阅读: ]

#文档大全网# 导语】以下是®文档大全网的小编为您整理的《简易VBA代码》,欢迎阅读!
简易,代码,VBA


合并工作

Sub Macro1()

Dim intRows As Integer

Dim intCols As Integer

For i = 2 To Sheets.Count

intRows = Sheets(i).UsedRange.Rows.Count

intCols = Sheets(i).UsedRange.Columns.Count

For j = 1 To intRows

Sheet1.Cells(j + 20 * (i - 2), 1) = Sheets(i).Name

For k = 1 To intCols

Sheet1.Cells(20 * (i - 2) + j, k + 1) = Sheets(i).Cells(j, k)

Next Next Next

End Sub


Sub 拆分多工作() '工作薄按工作表拆分成多个工作

Dim PATH As String

PATH = Application.ActiveWorkbook.PATH

Dim sht As Worksheet

Application.ScreenUpdating = False

For Each sht In Sheets

sht.Copy

ActiveWorkbook.SaveAs PATH & "\" & sht.Name & ".xls" '(工作表名称为文件名)

ActiveWorkbook.Close Next

Application.ScreenUpdating = True

End Sub


本文来源:https://www.wddqxz.cn/0a868313c950ad02de80d4d8d15abe23482f03d1.html

相关推荐