1.按 ALT+F11
将下列代码中的Sheet1后面的数字就可以了。比如将Sheet1改为Sheet2,Sheet3,即可导出对应的数据
方案1:
把所有记录保存到一个TXT文件中代码。

Sub txt1()

Dim file As String, arr, i

'定义文本文件的名称

file = ThisWorkbook.Path & "\巡检记录.txt"

'判断是否存在同名文本文件,存在先行删除

If Dir(file) <> "" Then Kill file

'将当前的数据读入数组

arr = Sheet2.Range("a1").CurrentRegion

'使用print语句将数组中所有数据写入文本文件

Open file For Output As #1

For i = 1 To UBound(arr)

Print #1, Join(Application.Index(arr, i), ",")

Next

'关闭文本文件

Close #1

End Sub

方案2:
把每条记录导出为一个TXT文件代码

Sub txt()

Dim i, j, arr(), brr(), myRow, myCol

arr = Sheet2.UsedRange

myRow = UBound(arr, 1)

myCol = UBound(arr, 2)

For i = 1 To myRow

Open ThisWorkbook.Path & "\" & arr(i, 1) & "1.txt" For Output As #1

Print #1, Join(Application.Index(arr, 1), ",")

Print #1, Join(Application.Index(arr, i), ",")

Close #1

Next

End Sub