乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > Excel如何用<em>VBA</em>把A1列的内容<em>写入</em&g

Excel如何用<em>VBA</em>把A1列的内容<em>写入</em&g

作者:乔山办公网日期:

返回目录: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

相关阅读

关键词不能为空
极力推荐
  • Excel2007:excel绘图在哪里-Excel电子表格

  • Excel电子表格,现在随着版本的提升,用excel2007的越来越多,但是很多工具大家都找不到在哪里了。包括一切其他的设置在哪里,一般情况下excel的原有功能还都有,大家只要细心去去找都

ppt怎么做_excel表格制作_office365_word文档_365办公网