How to obtain the data from cell from 500 .xls Excel files?

五迷三道 提交于 2019-12-02 10:02:13

I retrieve external data as follows:

Create a worksheet called "x" that specifies the following info for each item of data I want to get:

So I have the folder name, the file name, the worksheet name, and the cell reference for the items in columns A, B, C, D

Then run the following macro:

Sub GetExternalData()

    Dim wbPath As String, WorkbookName As String
    Dim WorksheetName As String, CellRef As String
    Dim Ret As String, i As Long, N As Long

    For i = 1 To Sheets("x").Cells(Rows.Count, 1).End(xlUp).Row

        wbPath = Sheets("x").Cells(i, 1).Value
        WorkbookName = Sheets("x").Cells(i, 2).Value
        WorksheetName = Sheets("x").Cells(i, 3).Value
        CellRef = Sheets("x").Cells(i, 4).Value

        Ret = "'" & wbPath & "[" & WorkbookName & "]" & _
              WorksheetName & "'!" & Range(CellRef).Address(True, True, -4150)

        Sheets("x").Cells(i, 5).Value = ExecuteExcel4Macro(Ret)
    Next i
End Sub

The macro will fill column E with the data.

In your case column A will be filled with replicated values since your files are all in a single folder.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!