VBA 输出TXT
答案:2 悬赏:30 手机版
解决时间 2021-04-05 10:04
- 提问者网友:树红树绿
- 2021-04-04 17:39
VBA 输出TXT
最佳答案
- 五星知识达人网友:猎心人
- 2021-04-04 17:47
Sub 提取xml()
Open "D:\主题.txt" For Output As #1
For r1 = 10 To 3000
For c1 = 7 To 8
Data1 = ActiveSheet.Cells(r1, c1).Value
If c1 <> 8 Then
Print #1, Data1; vbTab;
Else
Print #1, Data1
End If
Next c1
Next
Close #1
MsgBox "D:\主题.txt 保存成功!"
End Sub
或者:
Sub 提取xml()
Open "D:\主题.txt" For Output As #1
For r1 = 10 To 3000
Data1 = ActiveSheet.Cells(r1, 7).Value
Data2 = ActiveSheet.Cells(r1, 8).Value
Print #1, Data1; vbTab; Data2
Next
Close #1
MsgBox "D:\主题.txt 保存成功!"
End Sub追问老大,这样空白了,没数据了。追答怎么会呢?如果1楼有数据,这应该也有
Open "D:\主题.txt" For Output As #1
For r1 = 10 To 3000
For c1 = 7 To 8
Data1 = ActiveSheet.Cells(r1, c1).Value
If c1 <> 8 Then
Print #1, Data1; vbTab;
Else
Print #1, Data1
End If
Next c1
Next
Close #1
MsgBox "D:\主题.txt 保存成功!"
End Sub
或者:
Sub 提取xml()
Open "D:\主题.txt" For Output As #1
For r1 = 10 To 3000
Data1 = ActiveSheet.Cells(r1, 7).Value
Data2 = ActiveSheet.Cells(r1, 8).Value
Print #1, Data1; vbTab; Data2
Next
Close #1
MsgBox "D:\主题.txt 保存成功!"
End Sub追问老大,这样空白了,没数据了。追答怎么会呢?如果1楼有数据,这应该也有
全部回答
- 1楼网友:山河有幸埋战骨
- 2021-04-04 19:16
Private Sub CommandButton1_Click()
Open ThisWorkbook.Path & "\数据.txt" For Output As #1
For r1 = 10 To 100
For c1 = 7 To 8
Data1 = ActiveSheet.Cells(r1, c1).Value
If c1 <> 8 Then
Print #1, Data1 & vbTab
Else
Print #1, Data1
End If
Next c1
Next r1
Close #1
MsgBox "保存成功!"
End Sub追问谢谢回复!
发现在回车,能不能取消回车啊?
根据源码结果,出来的是:
100
333
我要的是:100 333 ‘一行一条数据,回车后则为次行的数据。
Open ThisWorkbook.Path & "\数据.txt" For Output As #1
For r1 = 10 To 100
For c1 = 7 To 8
Data1 = ActiveSheet.Cells(r1, c1).Value
If c1 <> 8 Then
Print #1, Data1 & vbTab
Else
Print #1, Data1
End If
Next c1
Next r1
Close #1
MsgBox "保存成功!"
End Sub追问谢谢回复!
发现在回车,能不能取消回车啊?
根据源码结果,出来的是:
100
333
我要的是:100 333 ‘一行一条数据,回车后则为次行的数据。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯