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

相关文章:

  • 2021-12-04
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-08-01
  • 2021-05-20
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2021-12-26
  • 2022-02-21
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
相关资源
相似解决方案