to Henry Jia: 你说的那种,是直接重新打开一个excel,而且,我的数据是日文的,会显示乱码, 我看书瞎写一段代码,Range("A3", "V3") = txt这行不理想,我希望的是数据输出到当前button下面 第三行开始直到最后 Private Sub Open_File_Click() Dim txt As String Open "D:\P-2_1.txt" For Input As #1 Do While Not EOF(1) Line Input #1, txt Range("A3", "V3") = txt Loop Close #1End Sub
Sub file_txt() Dim str_txt() As String, line As Integer, i As Integer, txt As String line = 1 Open "D:\a.txt" For Input As #1 Do While Not EOF(1) Line Input #1, txt str_txt = Split(txt, ",") For i = 0 To UBound(str_txt) Cells(line, i + 1).Value = str_txt(i) Next i line = line + 1 Loop Close #1 ActiveSheet.Range(Cells(1, 1), Cells(1, ActiveSheet.UsedRange.Columns.Count)).Interior.ColorIndex = 6 End Sub
Rows("1:1").Interior.ColorIndex = 6你可以用录制宏生成代码。
你说的那种,是直接重新打开一个excel,而且,我的数据是日文的,会显示乱码,
我看书瞎写一段代码,Range("A3", "V3") = txt这行不理想,我希望的是数据输出到当前button下面 第三行开始直到最后
Private Sub Open_File_Click()
Dim txt As String
Open "D:\P-2_1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, txt
Range("A3", "V3") = txt
Loop
Close #1End Sub
http://bbs.csdn.net/topics/390309082
Sub file_txt()
Dim str_txt() As String, line As Integer, i As Integer, txt As String
line = 1
Open "D:\a.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, txt
str_txt = Split(txt, ",")
For i = 0 To UBound(str_txt)
Cells(line, i + 1).Value = str_txt(i)
Next i
line = line + 1
Loop
Close #1
ActiveSheet.Range(Cells(1, 1), Cells(1, ActiveSheet.UsedRange.Columns.Count)).Interior.ColorIndex = 6
End Sub