テスト20



'--------------------------
'ファイル検索と処理
'--------------------------

Sub Sample()

Dim Hiduke As String
Hiduke = Replace(Date, "/", "")

Call FileSearch("C:\Users\User\Desktop\経理関連", Hiduke)

End Sub

'-----------------------------------

Sub FileSearch(Path As String, Target As String)

Dim FSO As Object
Dim Folder As Variant
Dim File As Variant
Dim wb As Workbook
Dim Mrow As String

Set FSO = CreateObject("Scripting.FileSystemObject")


For Each File In FSO.GetFolder(Path).Files

'    If File.Name Like Target Then
    If InStr(File.Name, Target) > 0 Then

       MsgBox File.Name
       Set wb = Workbooks.Open(File.Path)
       '-------------
       'いろいろ処理
       '-------------
       wb.ActiveSheet.Select
       Mrow = wb.ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
       MsgBox Mrow

       wb.Close SaveChanges:=True

    End If

Next File

Set wb = Nothing

End Sub