这段代码用一个模板,产生2025年每天的日报表备用。
Sub saleReport()
t1 = Timer()
Dim wb As Workbook
Dim ws As Worksheet
Dim templatePath As String
Dim oYear, oMonth, DaysInMonth As Integer
templatePath = "d:\templateSale.xlsx"
Set wb = Workbooks.Open(templatePath)
Set ws = wb.Sheets(1)
oYera = 2025
For oMonth = 1 To 12
DaysInMonth = Day(DateSerial(oYear, oMonth + 1, 1) - 1)
For oDay = 1 To DaysInMonth
fn = "2025年" + CStr(oMonth) + "月" + CStr(oDay) + "日的销售报表"
newFilePath = "d:\" + fn + ".xlsx"
ws.Name = fn
wb.SaveAs Filename:=newFilePath, FileFormat:=xlOpenXMLWorkbook
Next oDay
Next oMonth
wb.Close SaveChanges:=False
Set wb = Nothing
Set ws = Nothing
t2 = Timer()
Debug.Print t2 - t1
End Sub
程序运行了23秒。有无办法使用vba来并行调用我的4核cpu?将速度降低在几秒内?
Python或者c++这种多线程的语言试试,
用 Python multiprocessing 模块并发: