zoukankan      html  css  js  c++  java
  • EXCEL VBA中写了个宏把本EXCEL中的表数据批量导出为csv格式的文件

    Sub csv()
        Dim Fs, myFile As Object
        Dim myfileline As String 'txtfile的行数据
        Dim sht As Worksheet
       
        For Each sht In ThisWorkbook.Sheets
            ns = sht.Cells(1, 8)
            Set Fs = CreateObject("Scripting.FileSystemObject")   '建立filesytemobject
            Set myFile = Fs.createtextfile(ActiveWorkbook.Path + "csv" + ns + ".csv") '通过filesystemobject新建一个和xls文件同名的txt文件
            For i = 2 To 1000
                ra = sht.Cells(i, 3)
                If ra = "" Then Exit For
                rb = ""
                For j = 3 To 1000
                    ca = sht.Cells(2, j)
                    If ca = "" Then Exit For
                    If rb = "" Then
                        rb = sht.Cells(i, j).Value
                    Else
                        rb = rb & "," & sht.Cells(i, j).Value
                    End If
                Next j
                myFile.writeline (rb)
            Next i
            Set myFile = Nothing
            Set Fs = Nothing                   '关闭文件和filesystemobject对象
        Next
    End Sub

  • 相关阅读:
    团体程序设计天梯赛-练习集L1-002. 打印沙漏
    团体程序设计天梯赛-练习集L1-001. Hello World
    腾讯的一笔画游戏
    Educational Codeforces Round 11
    POJ 1149 PIGS
    POJ 3422 Kaka's Matrix Travels
    POJ 2914 Minimum Cut
    POJ 1815 Friendship
    POJ 1966 Cable TV Network
    BZOJ 1797: [Ahoi2009]Mincut 最小割
  • 原文地址:https://www.cnblogs.com/swtool/p/4541561.html
Copyright © 2011-2022 走看看