2,462
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Public Sub Main()
Dim strPath As String
Dim strTemp As String
Dim i As Long
strTemp = InputBox("请输入保存txt文件的路径:", "文件路径")
If ("" = strTemp) Then
Call MsgBox("没有指定输出路径,终止操作。", 64&, "提示信息")
Exit Sub
End If
strPath = strTemp & "\"
i = 2& ' 数据从第2行开始
Do
' 假设数据在当前工作簿的 Sheet1 中
strTemp = Trim$(Sheet1.Cells(i, 1).Value)
If ("" = strTemp) Then Exit Do ' 空单元格结束
Open strPath & strTemp & ".txt" For Output As #1
Print #1, strTemp; vbTab;
Print #1, Sheet1.Cells(i, 2).Value; vbTab;
Print #1, Sheet1.Cells(i, 3)
Close #1
i = 1& + i
Loop
If (2& = i) Then
Call MsgBox("没有数据输出。", 64&, "提示信息")
Else
Call MsgBox("输出操作完成。", 64&, "提示信息")
End If
End Sub