【发布时间】:2014-12-23 00:36:00
【问题描述】:
我正在尝试创建一个 Excel VBA 脚本,它将 2 列作为输入并将 的值输出到文本文件中。
例如
A1:123 B1:大道
A2:231 B2:另一条车道
我正在寻找一个看起来像这样的 txt 文件中的输出:
门牌号:123 街名:大道
----.
门牌号:231 街道名称:另一条车道
----.
基本上我正在寻找的是: "门牌号:"+A1+ "街道名称:"+B2 “-----”
我只能使用 1 列,但我坚持要添加第二列。
Sub CreatetestScript()
If Dir("C:\test.txt") <> "" Then
Kill ("C:\test.txt")
End If
Sheets("test").Select
Dim acolumn As String
r = 2
Do While Cells(r, 1) <> ""
acolumn = Cells(r, 1).Value
run (Cells(r, 1))
r = r + 1
Loop
End Sub
Sub run(ByVal acolumn As String)
Dim fileName As String
fileName = "C:\test.txt"
Open fileName For Append As #1
Print #1, ""
Print #1, "House Number = " + acolumn
Print #1, "--------------"
Close #1
End Sub
任何帮助将不胜感激
【问题讨论】: