Excel VBA将文件中的文本放入工作表中

时间:2017-01-09 15:05:42

标签: excel vba excel-vba

我想要的是:将数据放入记事本中,复制到工作表中(从范围A1开始)。

https://docs.jboss.org/author/display/WFLY8/DataSource+configuration

我尝试了什么:

Sub Test()
Dim testfile, textline

testfile = Application.GetOpenFilename()
Open testfile For Input As #1

Do Until EOF(1)
    Line Input #1, textline
Loop
Close #1

ActiveWorkbook.Sheets("Sheet1").Range("A1").Value = textline
End Sub

结果: Test

任何建议我为什么做错了,它不会抓住记事本中的所有文字,只是第一行?感谢。

1 个答案:

答案 0 :(得分:3)

你快到了:)。只需编写每个textline我单独的行,因为现在您只更改Range("A1").Value

Sub Test()
Dim testfile, textline

testfile = Application.GetOpenFilename()
Open testfile For Input As #1

i = 1
Do Until EOF(1)
    Line Input #1, textline
    ActiveWorkbook.Sheets("Sheet1").Range("A" & i).Value = textline
    i = i + 1
Loop
Close #1

End Sub
相关问题