這樣一個函數(shù):Private Function GetValue(path, file, sheet, ref)' 從未打開的Excel文件中檢索數(shù)據(jù)Dim arg As String' 確保該文件存在If Right(path, 1) <> "" Then path = path & "\"If Dir(path & file) = "" ThenGetValue = "File Not Found"Exit FunctionEnd If' 創(chuàng)建變量arg = "'" & path & "[" & file & "]" & sheet & "'!" & _Range(ref).Address(, , xlR1C1, False)' 執(zhí)行XLM 宏GetValue = ExecuteExcel4Macro(arg)End Function................................................................................................................在A工作簿中調(diào)用B工作簿和C工作簿中的數(shù)據(jù),調(diào)用B沒有任何問題,調(diào)用C工作簿中的數(shù)據(jù)出現(xiàn)#REF,如果把C工作簿執(zhí)行一次打開關(guān)閉動作(保存或不保存均可),再從A中調(diào)用C則問題消失。也就是說,同樣的代碼,調(diào)用一些工作簿表可以,另一些工作簿報錯,報錯的工作表執(zhí)行一次打開關(guān)閉動作問題消失。我確定路徑文件名都沒有問題?!案轮赶蚱渌臋n的鏈接”被選中。謝謝指導(dǎo)!
1 回答

蝴蝶不菲
TA貢獻1810條經(jīng)驗 獲得超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
提交
取消