在excel中,如何将每行数据的输出为一个独立的文本文件txt
3个回答
展开全部
在excel中,将每行数据的输出为一个独立的文本文件txt可用如下代码可以实现:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False '关闭屏幕刷新
Dim nRow&, ncolumn& '定义区域变量
nRow = Cells(Rows.Count, 1).End(3).Row '确定最后行行号
For i = 1 To nRow '在行中进行循环
ncolumn = Cells(i, Columns.Count).End(1).Column '确定每行最后列列号
Open ThisWorkbook.Path & "\文件" & i & ".txt" For Output As #1 '创建文本进行输入内容
Print #1, Join(Application.Transpose(Application.Transpose(Range(Cells(i, 1), Cells(i, ncolumn)))), ",") '输入此行内容,以","分隔内容
Close #1 '关闭文本
Next '下次循环
Application.ScreenUpdating = True '开启屏幕刷新,与前对应
MsgBox "导出完成" '完成友好提示
End Sub
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False '关闭屏幕刷新
Dim nRow&, ncolumn& '定义区域变量
nRow = Cells(Rows.Count, 1).End(3).Row '确定最后行行号
For i = 1 To nRow '在行中进行循环
ncolumn = Cells(i, Columns.Count).End(1).Column '确定每行最后列列号
Open ThisWorkbook.Path & "\文件" & i & ".txt" For Output As #1 '创建文本进行输入内容
Print #1, Join(Application.Transpose(Application.Transpose(Range(Cells(i, 1), Cells(i, ncolumn)))), ",") '输入此行内容,以","分隔内容
Close #1 '关闭文本
Next '下次循环
Application.ScreenUpdating = True '开启屏幕刷新,与前对应
MsgBox "导出完成" '完成友好提示
End Sub
展开全部
Sub 每一行保存为一个文本文件()
Dim Path As String
Dim yWb As Workbook
Dim xSh As Worksheet
Dim tRan As Range
Path = "E:\" '保存的路径
Set xSh = ActiveSheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each tRan In xSh.Range("A:A")
If tRan <> "" Then
Set yWb = Workbooks.Add
tRan.EntireRow.Copy yWb.Worksheets(1).Range("A1")
yWb.SaveAs Path & tRan.Row & ".txt", xlText
yWb.Saved = False
yWb.Close
Else
Exit For
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Dim Path As String
Dim yWb As Workbook
Dim xSh As Worksheet
Dim tRan As Range
Path = "E:\" '保存的路径
Set xSh = ActiveSheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each tRan In xSh.Range("A:A")
If tRan <> "" Then
Set yWb = Workbooks.Add
tRan.EntireRow.Copy yWb.Worksheets(1).Range("A1")
yWb.SaveAs Path & tRan.Row & ".txt", xlText
yWb.Saved = False
yWb.Close
Else
Exit For
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在所打的内容前面加一个'
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询