|
こんばんは
sは転記先という意味だけでは無いですよ。
各Excelファイルの格納フォルダ名を取得していますので、sが「千葉県」の時だけ
処理するようにすれば、
Sub test1()
Dim sFile As String
Dim i As Long
Dim fso As Object
Dim s As String
Set fso = CreateObject("Scripting.FileSystemObject")
With Application.FileSearch
.NewSearch
.LookIn = ThisWorkbook.Path & "\北高校"
.SearchSubFolders = True
.FileName = "*.xls"
.MatchTextExactly = True
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
s = fso.GetFile(.FoundFiles(i)).ParentFolder.Name
If s = "千葉県" Then
sFile = fso.GetParentFolderName(.FoundFiles(i))
sFile = "='" & sFile & "\[" & Dir(.FoundFiles(i)) & _
"]情報'!"
s = fso.GetFile(.FoundFiles(i)).ParentFolder.Name
With Worksheets(s).Cells(65536, 1).End(xlUp)
.Offset(1).Formula = sFile & "R1C1"
.Offset(1).Value = .Offset(1).Value
.Offset(1, 1).Formula = sFile & "R1C2"
.Offset(1, 1).Value = .Offset(1, 1).Value
End With
End If
Next
End If
End With
Set fso = Nothing
End Sub
|
|