I have some Excel files named by date, let's say from "2022-02-01.xlsx" to "2022-02-28.xlsx" How can I get values from a specific cell (eg: A1) from all these files for a worksheet (a master files)? I don't want to open these reports. I just want to update data from those files to the master files.
I'm not sure if the code below will work to other Excel version.
The code below works with my Excel 2010
Sub test()
p = "D:\test\" 'the path where all the files of the wb
s = "Sheet1" 'the sheet where the cell has the value wanted to know
c = "A1" '---> the cell where the value is wanted to know
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(p)
For Each oFile In oFolder.Files
f = oFile.Name
VL = "'" & p & "[" & f & "]" & _
s & "'!" & Range(c).Address(True, True, -4150)
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = _
oFile.Name & " cell A1 value is " & ExecuteExcel4Macro(VL)
Next
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.