テキストファイルを読み込んで処理する

テキストファイルを1行ずつ読み取り、表示するプログラムは以下のとおりです。

Sub test()
     Dim filemei As String
     Dim fileno As Long
     Dim line As String
     filemei = "c:¥test¥test.txt"

     '空いているファイル番号を取得します
     fileno = FreeFile

     'filemei のファイルをオープンします
     Open filemei For Input As #fileno

     'ファイルの終端まで繰り返します
     Do While Not EOF(fileno)

       '1行読み込みます
         Line Input #fileno, line
       'イミディエイトウィンドウに表示します
         Debug.Print (line)
    Loop
    'ファイルを閉じます
     Close #fileno
End Sub

VBAのお勉強 まとめにもどる

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2011 simple blog いろいろ勉強中 Suffusion theme by Sayontan Sinha