1. 程式人生 > >csv批量轉xls | excel按行數拆分

csv批量轉xls | excel按行數拆分

Csv批量轉xls:

Sub 轉換()



    ChDir "d:\user\828604\桌面"
   
    Dim sDir As String
    Dim curdir As String
   
    curdir = "d:\user\828604\桌面"
    sDir = Dir(curdir & "\*.csv")
   
    While Len(sDir)
        Workbooks.Open Filename:=curdir & "\" & sDir
        Dim temp As String
        temp = Left(sDir, Len(sDir) - 4)
        ActiveWorkbook.SaveAs Filename:=curdir & "\" & temp & ".xls", _
            FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
            ReadOnlyRecommended:=False, CreateBackup:=False
        ActiveWorkbook.Close
       sDir = Dir
      Wend


End Sub

excel按行數拆分:

Sub 拆分()
MsgBox ThisWorkbook.Sheets("Sheet3").UsedRange.Columns.Count
For i = 1 To 4
Set nb = Workbooks.Add
nb.SaveAs Filename:=ThisWorkbook.Path & "\" & i
nb.Activate
With ThisWorkbook.Sheets("Sheet3")
.Rows(1).Copy [a1]
.Range(.Cells(2500 * (i - 1) + 2, 1), .Cells(2500 * i + 1, 14)).Copy [a2]


End With
ActiveWorkbook.Save
ActiveWorkbook.Close
Next
End Sub