作者:乔山办公网日期:
返回目录:excel表格制作
For Each c In Worksheets("DXF").Range("H2:H213")
Print #1, trim(c.Value)
Next
Excel每行数据导出成txt.文件的VBA代码:
步骤一 设置宏先把加载宏安全性设为中或低
步骤二 插入模块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盘根目录下
如果你想放在其他目录,e799bee5baa6e79fa5e98193e4b893e5b19e335可以吧Open “D:\” &中的D:\改成你要的目录,但是目录不能有中文字符
可以使用如下的代码,复制如下代码到636f7079e79fa5e98193332VBA模块中运行即可。
如下代码代表4行4列,如果其余行或列数则可更改相应的数字。
具体步骤如下:
打开office excel;
Alt+F11打开VBA编辑器;
复制如下代码到模块中;
F5运行该模块;
按照提示进行如下步骤即可。
Sub xxx()
Dim myFile As String
Dim myText As String
Dim myString As String
Dim i As Single
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
.AllowMultiSelect = False
myFile = .SelectedItems(1)
End With
myText = Dir(myFile & "\" & "*.txt")
Do While Len(myText) <> 0
Open myFile & "\" & myText For Input As #1
myText = Split(Split(VBA.StrConv(InputB(LOF(1), 1), vbUnicode), Chr(10))(3), vbTab)(3) '4行4列,如果其余行或列数则更改相应的数字
Debug.Print myText
Close
myText = Dir
Loop
End Sub
Sub s()
pth = ThisWorkbook.Path
Open pth & "xxxx.txt" For Output As #1
For i = 39 To 1038
t = Cells(i, 2)
Print #1, t
Next
Close #1
End Sub