- ©«¤l
- 4901
- ¥DÃD
- 44
- ºëµØ
- 24
- ¿n¤À
- 4916
- ÂI¦W
- 277
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Office 20xx
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥x¥_
- µù¥U®É¶¡
- 2010-4-30
- ³Ì«áµn¿ý
- 2024-12-23
|
¦^´_ 7# luke - Sub Split_CSV()
- Dim Ar(), Ay()
- Set d = CreateObject("Scripting.Dictionary")
- Application.DisplayAlerts = False
- Application.ScreenUpdating = False
- fd = ThisWorkbook.Path & "\"
- fs = fd & "TEST21.csv"
- Set wb = Workbooks.Open(fs)
- yn = False
- With wb.Sheets(1) '¤À³ÎÀÉ®×
- k = .UsedRange.Columns.Count
- For Each a In .Range(.[A1], .Cells(.Rows.Count, 1).End(xlUp))
- If yn = False And InStr(a, ".csv") > 0 Then _
- yn = True: r = 1: _
- f = Replace(Replace(Replace(a, "[", ""), "]", ""), "*", ""): _
- Set sh = wb.Sheets.Add(after:=wb.Sheets(1))
- Ar = a.Resize(, k).Value
- With sh
- If yn = True Then
- .Cells(r, 1).Resize(, k) = Ar: r = r + 1
- ReDim Preserve Ay(s)
- Ay(s) = Join(Application.Transpose(Application.Transpose(Ar)), Chr(9))
- s = s + 1
- End If
- End With
- If InStr(a, "div") > 0 Then fs = fd & "µ²ªG\" & f: yn = False: sh.Move: ActiveWorkbook.SaveAs fd & "µ²ªG\" & f, 6: Workbooks(f).Close: d(f) = Join(Ay, Chr(10)): Erase Ay: s = 0
- Next
- End With
- wb.Close 0
- fs = Dir(fd & "*.csv")
- Do Until fs = ""
- If fs <> "TEST21.csv" Then
- Set wb = Workbooks.Open(fd & fs)
- With wb.Sheets(1)
- k = .UsedRange.Columns.Count
- ReDim Ar(k)
- Ar(0) = "[*" & fs & "*]"
- For i = 1 To k - 1
- Ar(i) = ""
- Next
- ReDim Preserve Ay(s)
- Ay(s) = Join(Ar, Chr(9))
- s = s + 1
- For Each a In .UsedRange.Columns(1).Cells
- Ar = a.Resize(, k).Value
- ReDim Preserve Ay(s)
- Ay(s) = Join(Application.Transpose(Application.Transpose(Ar)), Chr(9))
- s = s + 1
- Next
- ReDim Preserve Ay(s)
- Ay(s) = Join(Array("", "", "", "", "", "", "", ""), Chr(9))
- s = s + 1
- ReDim Ar(k)
- Ar(0) = "[*div*]"
- For i = 1 To k - 1
- Ar(i) = ""
- Next
- ReDim Preserve Ay(s)
- Ay(s) = Join(Ar, Chr(9))
- s = s + 1
- d(fs) = Join(Ay, Chr(10))
- Erase Ay: s = 0
- End With
- wb.Close 0
- End If
- fs = Dir
- Loop
- With Worksheets.Add
- .[A1].Resize(d.Count, 1) = Application.Transpose(d.keys)
- .[A1].Resize(d.Count, 1).Sort key1:=.[A1], Header:=xlNo
- Ar = .[A1].Resize(d.Count, 1).Value
- r = 1
- For Each ky In Ar '²Õ¦XÀÉ®×
- an = Split(d(ky), Chr(10))
- For j = 0 To UBound(an)
- ak = Split(an(j), Chr(9))
- .Cells(r, 1).Resize(, UBound(ak) + 1) = ak
- r = r + 1
- Next
- r = r + 1
- Next
- .Move
- ActiveWorkbook.SaveAs fd & "µ²ªG\" & "TEST21OK.csv", 6
- ActiveWorkbook.Close 1
- End With
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
½Æ»s¥N½X |
|