我想知道如何使用Excel VBA定义单元格位置的特定文件路径?我正在尝试将值加载到nCount
,这是在定义位置的另一个文件中的计数。更像是将单元格中的值分配给nCount
。
nCount = "G:\ABC\[FILE FOR 2016-2017.xlsx]Master!$A$1"
它给了我一个错误:
运行时错误' 13:&#34 ;; "类型不匹配
答案 0 :(得分:0)
您可以使用和 Excel4 宏从已关闭的工作簿中获取值。这是一个典型的例子:
Sub Sample()
Dim wbPath As String, wbName As String
Dim wsName As String, CellRef As String
Dim Ret As String
wbPath = "C:\TestFolder\"
wbName = "ABC.xls"
wsName = "xxx"
CellRef = "B9"
Ret = "'" & wbPath & "[" & wbName & "]" & _
wsName & "'!" & Range(CellRef).Address(True, True, -4150)
MsgBox Ret & vbCrLf & ExecuteExcel4Macro(Ret)
End Sub