作者:乔山办公网日期:
返回目录:excel表格制作
我可以帮你写个VBA代码,还需要吗?
如果需要,请告知要生成的Sheet名,LMNO四列从哪行开始输出。
Sub 宏抄1()
'
' 宏1 宏
'
' 快捷键袭: Ctrl+q
'
Dim i As Long
Dim abc, xtxt, n
Set abc = CreateObject("scripting.filesystemobject")
Set ntxt = abc.opentextfile("d:\n.txt", 8, True)
ntxt.writeline n '数据写入文知本文档道"d:\n.txt"
For i = 1 To 100
ntxt.writeline Range("A" & i).Value
Next i
ntxt.Close
Set abc = Nothing
End Sub
Excel每行数据导出成txt.文件的VBA代码:
步骤一 设置宏先e79fa5e98193e58685e5aeb9335把加载宏安全性设为中或低
步骤二 插入模块alt+f11打开VBA编辑器
打开 菜单栏》插入》模块,把下面代码加进去
Sub DaoChu()
Dim I As Integer, J As Long, RW As Long
For I = 1 To ActiveSheet.UsedRange.Columns.Count
Open ThisWorkbook.Path & "\" & Cells(1, I) & ".txt" For Output As 1
For J = 2 To Cells(65536, I).End(3).Row
Print #1, Cells(J, I).Value
Next J
Close 1
Next I
MsgBox "数据导出完毕!", vbOKOnly, "导出成功"
End Sub
步骤三 保存以后关闭EXCEL步骤四 测试再重新打开excel,按ctrl+shift+P就完成导出了,文件在D盘根目录下
如果你想放在其他目录,可以吧Open “D:\” &中的D:\改成你要的目录,但是目录不能有中文字符
用法:运行代码,结果会生成在excel所在的文件夹下面的e799bee5baa6e4b893e5b19e331output.txt中。如果想指定运算区域,则将,选中你想要挑选的区域,'Set zon = Application.InputBox("please choose the zone", Type:=8)前的 ' 去掉然后添加到 Set zon = Range("A1:Z1000")前面。
Sub output()
Dim zon As Range
Dim ttr, ttc As String
Open ThisWorkbook.Path & "\output.txt" For Output As #1
Set zon = Range("A1:Z1000")
'Set zon = Application.InputBox("please choose the zone", Type:=8)
For Each Rng In zon
If Rng.Font.Color = 255 Then
ttr = Cells(Rng.Row, 1)
ttc = Cells(1, Rng.Column)
Print #1, ttr, ttc, Rng
End If
Next
Close #1
End Sub