这样一个函数:Private Function GetValue(path, file, sheet, ref)' 从未打开的Excel文件中检索数据Dim arg As String' 确保该文件存在If Right(path, 1) <> "" Then path = path & "\"If Dir(path & file) = "" ThenGetValue = "File Not Found"Exit FunctionEnd If' 创建变量arg = "'" & path & "[" & file & "]" & sheet & "'!" & _Range(ref).Address(, , xlR1C1, False)' 执行XLM 宏GetValue = ExecuteExcel4Macro(arg)End Function................................................................................................................在A工作簿中调用B工作簿和C工作簿中的数据,调用B没有任何问题,调用C工作簿中的数据出现#REF,如果把C工作簿执行一次打开关闭动作(保存或不保存均可),再从A中调用C则问题消失。也就是说,同样的代码,调用一些工作簿表可以,另一些工作簿报错,报错的工作表执行一次打开关闭动作问题消失。我确定路径文件名都没有问题。“更新指向其他文档的链接”被选中。谢谢指导!
1 回答
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
Sub Sample()
Dim wbPath As String, wbName As String
Dim wsName As String, cellRef As String
Dim Ret As String
'wbPath = "C:\Documents and Settings\Siddharth Rout\Desktop\"
wbPath = "C:\Users\my.name\Desktop\"
wbName = "QOS DGL stuff.xls"
wsName = "ACL"
cellRef = "C3"
Ret = "'" & wbPath & "[" & wbName & "]" & _
wsName & "'!" & Range(cellRef).Address(True, True, -4150)
MsgBox ExecuteExcel4Macro(Ret)
End Sub
添加回答
举报
0/150
提交
取消