我正在尝试将已关闭工作簿中的单元格中的数据复制到另一个工作簿中,而无需打开原始工作簿。
我展示的代码很远......有效,但我需要能够将数据写入打开的工作簿上的某个单元格。
Private Function GetValue(path, file, sheet, ref)
' 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 TestGetValue2()
p = "F:\excel_Project"
f = "Book1.xlsx"
s = "Sheet1"
a = "A1"
GetValue(p, f, s, a) = ("A1")
End Sub