|
求哪位老师帮忙下,将下面VBA改下,我需要拆分到文件夹后不覆盖文件夹里面原来的文件的,下面这个VBA会覆盖原来的文件,麻烦哪位老师修改下
Sub 拆分为工作簿()
Dim arr As Variant
Dim d As Object
Dim brr()
Dim i, s As Integer
Dim wb As Workbook
arr = Sheet1.UsedRange
Set d = CreateObject("scripting.dictionary")
For i = 2 To UBound(arr)
d(arr(i, 1)) = ""
Next i
Set fso = CreateObject("Scripting.FileSystemObject")
Application.SheetsInNewWorkbook = 1
For Each k In d.keys
Set wb = Workbooks.Add
ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
n = 0
If fso.FolderExists(ThisWorkbook.Path & "\" & k) Then
Set f = fso.GetFolder(ThisWorkbook.Path & "\" & k)
f.Delete
End If
On Error Resume Next
MkDir ThisWorkbook.Path & "\" & k
For i = 2 To UBound(arr)
If arr(i, 1) = k Then
n = n + 1
For s = 1 To UBound(arr, 2)
brr(n, s) = arr(i, s)
Next s
End If
Next i
wb.Worksheets(1).[a1].Resize(1, UBound(arr, 2)) = arr
wb.Worksheets(1).[a2].Resize(n, UBound(brr, 2)) = brr
wb.SaveAs Filename:=ThisWorkbook.Path & "\" & k & "\" & k & Format(Date, "yyyymmdd") & ".xlsx"
wb.Close False
Next k
End Sub
|
|