|
コマンド・プロンプトの "DIRコマンド" を使うコードです。
管理.xlsに入れて試してみて下さい。
ただし、そちらに「似た条件」のテストしかしていませんので、あしからず。
Sub Test_COM_DIR()
Dim WshShell As Object, oExec As Object
Dim i As Long, Pt As Long
Dim St As String, Lk As String
Const CmdSt As String = _
"CMD.EXE /C DIR ""C:\北高校\*.xls"" /S /B"
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(CmdSt): i = 1
With Worksheets("千葉")
.Cells.ClearContents
Do Until oExec.StdOut.AtEndOfStream
St = oExec.StdOut.ReadLine
If InStr(1, St, "千葉県") > 0 Then
Pt = InStrRev(St, "\")
Lk = "='" & Left$(St, Pt) & "[" & _
Mid$(St, Pt + 1) & "]情報'!A1"
i = i + 1
With .Cells(i, 1).Resize(, 2)
.Formula = Lk
.Value = .Value
End With
End If
Loop
.Range("A1:B1").Value = Array("氏名", "住所")
End With
Set oExec = Nothing: Set WshShell = Nothing
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
|
|