特定フォルダ内のファイルを処理する

あるフォルダに入っているファイルを全て処理するような場合のプログラムです。

Sub test()
    Dim sagasuFilemei   As String
    Dim sagasuFoldermei As String
    sagasuFoldermei = "c:¥csv¥"
    
    ' 先頭のファイル名の取得
    sagasuFilemei = Dir(sagasuFoldermei & "*.csv", vbNormal)
    
    ' ファイルが見つからなくなるまで繰り返す
    Do While sagasuFilemei <> ""
        
        'ファイル名をイミディエイトウィンドウに表示します
        Debug.Print (sagasuFilemei)
        
        ' 次のファイル名を取得
        sagasuFilemei = Dir()
    
    Loop
End Sub

これで、c:¥csv¥ 内の、拡張子がcsvのファイル名一覧が表示されます。
なお、上記のプログラムではサブフォルダには対応していません。
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