龙空技术网

使用vba将Excel 文件转成 CSV 文件

Excel可以这么玩 41

前言:

现时我们对“java csv转换为excel”大约比较看重,你们都需要学习一些“java csv转换为excel”的相关文章。那么小编在网上网罗了一些对于“java csv转换为excel””的相关知识,希望大家能喜欢,各位老铁们快快来了解一下吧!

使用vba将Excel中的内容写入文本文件,保存为txt或csv格式。

方法一:

Sub toCSV()    Dim sht As Worksheet    Dim i As Integer, j As Integer    Dim arr()    Dim line As String        For Each sht In Sheets        If Int(sht.Name) Mod 2 = 1 Then            arr = sht.Range("a1").CurrentRegion            Open "C:\Users\heju\Desktop\csv & xlsx\" & sht.Name & ".csv" For Output As #1                For i = LBound(arr) To UBound(arr)                    line = ""                    For j = LBound(arr, 2) To UBound(arr, 2)                        line = line & arr(i, j) & ","                    Next                    line = Left(line, Len(line) - 1)                    Print #1, line                Next            Close        End If    NextEnd Sub

方法二:

Sub shttobook()    Dim sht As Worksheet, path As String        Application.ScreenUpdating = False    Application.DisplayAlerts = False    path = ThisWorkbook.path & "\csv & xlsx"    For Each sht In Worksheets        sht.Copy        ActiveWorkbook.SaveAs Filename:=path & "\" & sht.Name & ".csv", FileFormat:=xlCSV        ActiveWorkbook.Close    Next    Application.DisplayAlerts = True    Application.ScreenUpdating = TrueEnd Sub

标签: #java csv转换为excel