Excelvba从文件中逐行读取并写入excel中

Sub 読み込む()
    Dim result As Long
    Dim dialog As FileDialog
    Set dialog = Application.FileDialog(msoFileDialogOpen)
    dialog.ButtonName = "開く"
    result = dialog.Show
    If result = -1 Then
        Cells(1, 5).Value = "ファイルが選択されました。" & dialog.SelectedItems.Item(1)
        Open dialog.SelectedItems.Item(1) For Input As #1
        Dim inputstr As String
        Dim counter As Integer
        counter = 2
        Do While Not EOF(1)
            Input #1, inputstr
            Cells(counter, 2).Value = inputstr
            counter = counter + 1
       Loop
       Close #1
    End If
End Sub

原文地址:https://www.cnblogs.com/jiangwenwen1/p/10360227.html