根据打开的工作表中单元格的内容从已closures的工作簿获取数据

我想尝试从封闭的工作簿/工作表中的单个单元格获取数据,但文件名取决于打开的工作簿/工作表中的单元格。 这是我开始的代码,但不能让它正常工作。

Private Function GetValue(path, file, sheet, ref) path = "Z:\Jobs\" file = "4817.xlsx" sheet = "RTR1" ref = "A13" ' Retrieves a value from a closed workbook Dim arg As String ' Make sure the file exists If Right(path, 1) <> "\" Then path = path & "\" If Dir(path & file) = "" Then GetValue = "File Not Found" Exit Function End If ' Create the argument arg = "'" & path & "[" & file & "]" & sheet & "'!" & _ Range(ref).Range("A1").Address(, , xlR1C1) ' Execute an XLM macro GetValue = ExecuteExcel4Macro(arg) End Function 

 Sub TestGetValue() path = "Z:\Jobs\" file = "Macine Planning.xlsx" sheet = "Data" Application.ScreenUpdating = False For r = 1 To 30 For C = 1 To 18 a = Cells(r, C).Address Cells(r, C) = GetValue(path, file, sheet, a) Next C Next r Application.ScreenUpdating = True End Sub 

谢谢你的帮助。