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

posted @ 2019-02-10 20:52  姜文文  阅读(3166)  评论(0编辑  收藏  举报