HTML,CSS,PHP,ワードプレスカスタマイズ 技術情報資料

ファイル/フォルダー一覧取得 VBA よく使う小技

よく使うんだけど、よくわすれる、ファイル/フォルダー一覧の取得パーツ
 
    Dim File_Collection As Object
    Dim File_List As Variant
    Dim cnt As Integer
    Dim inpd
    
    'inpd にターゲットのフォルダーパスをいれる
    inpd = ActiveWorkbook.Path + "\rank_form"
    
    'フォルダー一覧を取得する場合
    'Set File_Collection = CreateObject("Scripting.FileSystemObject").GetFolder(inpd).SubFolders
    'ファイル一覧を取得する場合
    Set File_Collection = CreateObject("Scripting.FileSystemObject").GetFolder(inpd).Files
    
    ComboBox2.Clear
    cnt = 0
    For Each File_List In File_Collection
        If File_List.Name <> "." And File_List.Name <> ".." Then
            cnt = cnt + 1
            ComboBox2.AddItem (File_List.Name)
        End If
    Next
    If ComboBox2.ListCount > 0 Then
        ComboBox2.ListIndex = 0
    End If

スポンサーリンク

関連記事

スポンサーリンク

カテゴリー