经过几次调整,我终于实现了我想要的。
第一行将是输出txt文件的头。
Sub TextExportCol()
Dim strPath$, x&, i%, txt$
strPath = ThisWorkbook.Path & "\"
For x = 1 To Cells(1, Columns.Count).End(xlToLeft).Column 'Loop from column 1 to end column
Open strPath & Cells(1, x).Value & ".txt" For Output As #1
txt = ""
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row 'How many rows to include, from row 1 to end
txt = txt & Cells(i, x).Value & vbNewLine
Next i
Print #1, Left(txt, Len(txt) - 1)
Close #1
Next x
MsgBox "The text files can be found in " & strPath & ".", 64, "Complete"
End Sub