Attribute VB_Name = "模块"
Sub 由模板生成()
Attribute 由模板生成.VB_ProcData.VB_Invoke_Func = " n14"
Dim outdir As String
'outdir 输出文件目录
outdir = "D:output"
If dir(outdir) = "" Then
MkDir outdir
End If
If Sheets.Count > 2 Then
For i = 3 To Sheets.Count
Sheets(3).Delete
Next
End If
For i = 2 To 4 Step 1
Sheets("模板").Copy After:=Sheets(Worksheets.Count)
Sheets(Worksheets.Count).Name = Sheets("数据源").Cells(i, 1)
ActiveSheet.Cells(2, 2) = Sheets("数据源").Cells(i, 1)
ActiveSheet.Cells(3, 2) = Sheets("数据源").Cells(i, 2)
ActiveSheet.Cells(4, 2) = Sheets("数据源").Cells(i, 3)
Next
ActiveWorkbook.Save
' True:输出为单个文件
' False:输出到当前工作簿其他sheet
If True Then
If Sheets.Count > 2 Then
For i = 3 To Sheets.Count
Sheets(3).Select
file = Sheets(3).Name
Sheets(3).Move
ActiveWorkbook.SaveAs Filename:=outdir + file + ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Close
Next
End If
End If
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.Quit
End Sub
最后
以上就是开心小馒头最近收集整理的关于vba脚本(通过模板和数据表生成多个表)的全部内容,更多相关vba脚本(通过模板和数据表生成多个表)内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复