Sub 创建文本文件()
Dim fso As New Scripting.FileSystemObject
Dim ostream As Scripting.TextStream
Dim sfname As String
Dim str1 As String
sfname = Application.InputBox(prompt:="请输入文本文件的名称", _
Title:="输入文件名称", Type:=2)
If sfname = "False" Or sfname = "" Then Exit Sub
sfname = ThisWorkbook.Path & "\" & sfname & ".txt"
Set ostream = fso.CreateTextFile(Filename:=sfname, overwrite:=True)
r = 2
Do
With Sheet1
str1 = ""
For i = 1 To 3
str1 = str1 & .Cells(r, i) & ","
Next
End With
ostream.WriteLine Left(str1, Len(str1) - 1)
Loop Until IsEmpty(Sheet1.Cells(r, 1))
ostream.Close
MsgBox "文本文件创建成功!"
Set ostream = Nothing
Set fso = Nothing
End Sub