Try something like this code...
Sub Button1_Click()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim fullfilename As String
Dim filename As String
Dim oFSO As Object
Dim oFolder As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(Range("B1").Value)
Set wb1 = ActiveWorkbook
For Each oFile In oFolder.Files
Range("B2").Value = oFile.Name
Application.ScreenUpdating = False
fullfilename = Range("B1").Value & Range("B2").Value
filename = Range("B2").Value
Workbooks.Open fullfilename
Set wb2 = ActiveWorkbook
With Range("F2:F" & Cells(Rows.Count, "A").End(xlUp).Row)
.Formula = "=AVERAGE($A$1:A1)"
End With
With Range("G2:G" & Cells(Rows.Count, "B").End(xlUp).Row)
.Formula = "=MEDIAN($B$2:B2)"
End With
With Range("H2:H" & Cells(Rows.Count, "C").End(xlUp).Row)
.Formula = "=AVERAGE($C$1:C1)"
End With
Workbooks(filename).Close SaveChanges:=True
wb1.Activate
Application.ScreenUpdating = True
Next oFile
End Sub
as in attached workbook.
Bookmarks