|
はじめまして
Sub test_1()
Dim myFile As String, File_Path As String, File_Name As String, Fld_Path As String
Dim myList As Variant
Dim myCount As Integer, myChk As Boolean
Dim i As Integer
Const myDir As String = "D:\mm\oo\tt\ee\" '検索ディレクトリ
myFile = CStr(Cells(1, 1)) & "*" 'ファイル名(セルの値)
'指定階層検索
myChk = False
File_Name = myDir & myFile
File_Path = Dir(File_Name, vbNormal)
Do While File_Path <> ""
If File_Path Like myFile Then
Workbooks.Open Filename:=myDir & File_Path
myChk = True
Exit Do
End If
File_Path = Dir()
Loop
If myChk = True Then
Exit Sub
End If
'指定階層内フォルダ検索
myCount = 0
ReDim myList(myCount)
File_Path = Dir(myDir, vbDirectory)
Do While File_Path <> ""
myList(myCount) = myDir & File_Path
myCount = myCount + 1
ReDim Preserve myList(myCount)
File_Path = Dir()
Loop
For i = 0 To myCount - 1
On Error Resume Next
File_Name = myList(i) & "\" & myFile
File_Path = Dir(File_Name, vbNormal)
Do While File_Path <> ""
If File_Path Like myFile Then
Workbooks.Open Filename:=myList(i) & "\" & File_Path
myChk = True
Exit Do
End If
File_Path = Dir()
Loop
If myChk = True Then
Exit For
End If
Next i
If myChk = False Then
MsgBox "ファイルが見つかりません。"
End If
End Sub
というセルに入力したファイル名で始まるファイルを開くマクロですが、
今の状態では2階層しか検索できません。
3階層のものをつくりたいのですが、どのように追加したらよいでしょうか??
|
|