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