Sub Run()
Dim tar_wb As Workbook
Set tar_wb = CreateWorkbook
Call MergeContent(tar_wb)
End Sub
'函数名: CreateWorkbook
'接受参数:无
'返回值:Workbook(返回创建的Workbook)
'说明:创建一个Excel文件,存放合并的数据
Private Function CreateWorkbook() As Workbook
Dim fileName As String
Dim filePath As String
Dim nowDate As String
nowDate = CDate(Now())
nowDate = Replace(nowDate, ":", "")
nowDate = Replace(nowDate, "/", "")
nowDate = Replace(nowDate, " ", "_")
filePath = ThisWorkbook.path & "\"
fileName = filePath & nowDate & "_汇总表.xlsx"
Dim newBook As Workbook
Set newBook = Workbooks.Add
With newBook
.SaveAs fileName
End With
Set CreateWorkbook = newBook
End Function
'函数名: MergeContent
'接受参数:targetWorkbook(合并后的数据存放的Workbook对象)