第1个回答 2018-05-17
Sub 于生成文件()
Dim Rng As Range, Sh As Worksheet, Sh1 As Worksheet, Wb As Workbook
Dim Dic As Object, i&, j&, Filn$
Set Dic = CreateObject("Scripting.Dictionary")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
Filn = Dir(ThisWorkbook.Path & "\" & Format(Date, "于yyyymmdd生成*"), vbDirectory)
Do While Len(Filn) <> 0
Dic(Filn) = ""
Filn = Dir
Loop
If Not Dic.Exists(Format(Date, "于yyyymmdd生成")) Then MkDir ThisWorkbook.Path & "\" & Format(Date, "于yyyymmdd生成")
Set Dic = Nothing
For Each Sh In ThisWorkbook.Worksheets
Set Wb = Workbooks.Add
For i = 2 To Sh.Cells(Rows.Count, 1).End(xlUp).Row
Set Sh1 = Wb.Worksheets.Add
Sh1.Name = Sh.Cells(i, 1)
[A5] = Sh.Cells(i, 1)
[B3] = Sh.Cells(i, 2)
[C7] = Sh.Cells(i, 3)
[D11] = Sh.Cells(i, 4)
[E9] = Sh.Cells(i, 5)
Next i
Wb.SaveAs ThisWorkbook.Path & Format(Date, "\\于yyyymmdd生成\\") & Sh.Name
Wb.Close
Next Sh
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub本回答被提问者采纳