aaa fdsa bfs2 将这一行的2,3列的数据保存到txt里面,换行,txt的文件名为aaa。
bbb fdsag hgrtde 将这一行的2,3列的数据保存到txt里面,换行,txt的文件名为bbb。
ccc afdsa fdsaf 将这一行的2,3列的数据保存到txt里面,换行,txt的文件名为ccc。
... ... ... 同上
多谢!
5 个解决方案
#1
Sub abc()
Dim i As Long
For i = 1 To 3
Dim Filename As String
Filename = Application.ActiveWorkbook.Path & "\" & Cells(i, 1) & ".txt"
Open Filename For Append As #1
Print #1, Cells(i, 2)
Print #1, Cells(i, 3)
Close #1
Next
End Sub
Dim i As Long
For i = 1 To 3
Dim Filename As String
Filename = Application.ActiveWorkbook.Path & "\" & Cells(i, 1) & ".txt"
Open Filename For Append As #1
Print #1, Cells(i, 2)
Print #1, Cells(i, 3)
Close #1
Next
End Sub
#2
这个简单:
在你的 VBA 代码中加入这个过程,调用它就可以了:
在你的 VBA 代码中加入这个过程,调用它就可以了:
Sub PutText()
Dim nFile&, i&, strTemp$
i = 1
Do
i = i + 1
strTemp = Cells(i, 1).Value
If (Len(strTemp) = 0) Then Exit Do
nFile = FreeFile()
Open "x:\temp\" & strTemp & ".txt" For Output As #nFile
Print #nFile, Cells(i, 2).Value
Print #nFile, Cells(i, 3).Value
Close #nFile
Loop
End Sub
#3
注意这句:
Open "x:\temp\" & strTemp & ".txt" For Output As #nFile
"x:\temp\"是我测试时用的路径,你要把它改成你需要的路径。
Open "x:\temp\" & strTemp & ".txt" For Output As #nFile
"x:\temp\"是我测试时用的路径,你要把它改成你需要的路径。
#4
Sub PutText()
Dim nFile&, i&, strTemp$
i = 1
Do
i = i + 1
strTemp = Cells(i, 1).Value
If (Len(strTemp) = 0) Then Exit Do
nFile = FreeFile()
Open "D:\temp\" & strTemp & ".txt" For Output As #nFile
Print #nFile, Cells(i, 2).Value
Print #nFile, Cells(i, 3).Value
Close #nFile
Loop
End Sub
Dim nFile&, i&, strTemp$
i = 1
Do
i = i + 1
strTemp = Cells(i, 1).Value
If (Len(strTemp) = 0) Then Exit Do
nFile = FreeFile()
Open "D:\temp\" & strTemp & ".txt" For Output As #nFile
Print #nFile, Cells(i, 2).Value
Print #nFile, Cells(i, 3).Value
Close #nFile
Loop
End Sub
#5
学习了!
#1
Sub abc()
Dim i As Long
For i = 1 To 3
Dim Filename As String
Filename = Application.ActiveWorkbook.Path & "\" & Cells(i, 1) & ".txt"
Open Filename For Append As #1
Print #1, Cells(i, 2)
Print #1, Cells(i, 3)
Close #1
Next
End Sub
Dim i As Long
For i = 1 To 3
Dim Filename As String
Filename = Application.ActiveWorkbook.Path & "\" & Cells(i, 1) & ".txt"
Open Filename For Append As #1
Print #1, Cells(i, 2)
Print #1, Cells(i, 3)
Close #1
Next
End Sub
#2
这个简单:
在你的 VBA 代码中加入这个过程,调用它就可以了:
在你的 VBA 代码中加入这个过程,调用它就可以了:
Sub PutText()
Dim nFile&, i&, strTemp$
i = 1
Do
i = i + 1
strTemp = Cells(i, 1).Value
If (Len(strTemp) = 0) Then Exit Do
nFile = FreeFile()
Open "x:\temp\" & strTemp & ".txt" For Output As #nFile
Print #nFile, Cells(i, 2).Value
Print #nFile, Cells(i, 3).Value
Close #nFile
Loop
End Sub
#3
注意这句:
Open "x:\temp\" & strTemp & ".txt" For Output As #nFile
"x:\temp\"是我测试时用的路径,你要把它改成你需要的路径。
Open "x:\temp\" & strTemp & ".txt" For Output As #nFile
"x:\temp\"是我测试时用的路径,你要把它改成你需要的路径。
#4
Sub PutText()
Dim nFile&, i&, strTemp$
i = 1
Do
i = i + 1
strTemp = Cells(i, 1).Value
If (Len(strTemp) = 0) Then Exit Do
nFile = FreeFile()
Open "D:\temp\" & strTemp & ".txt" For Output As #nFile
Print #nFile, Cells(i, 2).Value
Print #nFile, Cells(i, 3).Value
Close #nFile
Loop
End Sub
Dim nFile&, i&, strTemp$
i = 1
Do
i = i + 1
strTemp = Cells(i, 1).Value
If (Len(strTemp) = 0) Then Exit Do
nFile = FreeFile()
Open "D:\temp\" & strTemp & ".txt" For Output As #nFile
Print #nFile, Cells(i, 2).Value
Print #nFile, Cells(i, 3).Value
Close #nFile
Loop
End Sub
#5
学习了!