宏将整个文本文件导入单个单元格

时间:2016-11-20 18:48:51

标签: excel-vba vba excel

我需要创建一个Excel宏来将txt文件中的每个字符导入到列中的单个单元格中。例如。如果文字是"测试",那么" t"会去A1," e"到A2,等等在电子表格中。谢谢!

1 个答案:

答案 0 :(得分:1)

尝试根据您的需求进行调整:

Sub Macro1()
    Dim s As String, i As Long, j As Long
    Open "C:\TestFolder\Inputs.txt" For Input As #1 Len = 1
    i = 1
    j = 1

    Do Until EOF(1)
        s = Input(1, #1)
        Cells(i, j) = s
        i = i + 1
        If i > Rows.Count Then
            i = 1
            j = j + 1
        End If
    Loop
    Close #1
End Sub