!!!Excel VBA ディレクトリの再帰処理 [Excel VBA]{{category VBAソース片}} !!FileSystemObjec http://msdn.microsoft.com/ja-jp/library/cc392182.aspx ディレクトリの再帰処理をDir関数を使って書こうと思ったら、困難そうなので、[FileSystemObject|http://msdn.microsoft.com/ja-jp/library/cc409798.aspx]を使う。 Const FileAttrNormal = 0 Const FileAttrReadOnly = 1 Const FileAttrHidden = 2 Const FileAttrSystem = 4 Const FileAttrVolume = 8 Const FileAttrDirectory = 16 Const FileAttrArchive = 32 Const FileAttrAlias = 64 Const FileAttrCompressed = 128 Private fso As Object Public Sub recursiveProc() Dim d As String Dim folder As Object Set fso = CreateObject("Scripting.FileSystemObject") Set folder = fso.GetFolder("c:\") Call traverse(folder) End Sub Private Function traverse(path As Object) As Object Dim sfs As Object Dim sf As Object Dim fs As Object Dim f As Object If path.Attributes And FileAttrDirectory Then Debug.Print "DIR : " & path Set sfs = path.subFolders For Each sf In sfs Call traverse(sf) Next Set fs = path.Files For Each f In fs Call traverse(f) Next End If If path.Attributes And FileAttrArchive Then Debug.Print "FILE : " & path End If End Function