簡體   English   中英

如何從新工作表的許多 Excel 文件中的特定單元格獲取值

[英]How to get values from a specific cell from many Excel files for a new worksheet

我有一些按日期命名的 Excel 文件,比方說從“2022-02-01.xlsx”到“2022-02-28.xlsx” 我如何從所有這些文件的特定單元格(例如:A1)中獲取值工作表(主文件)? 我不想打開這些報告。 我只想將這些文件中的數據更新到主文件。

我不確定下面的代碼是否適用於其他 Excel 版本。
下面的代碼適用於我的 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

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM