2016-10-04 152 views
1

我在想如何使用Excel VBA定义单元格位置的特定文件路径?我试图加载一个值到nCount这是另一个文件在一个定义的位置的计数。所以更像是将单元格中的值分配给nCount使用Excel VBA确定单元格位置的文件路径

nCount = "G:\ABC\[FILE FOR 2016-2017.xlsx]Master!$A$1" 

它给了我一个错误:

Run-time error '13:"; "Type Mismatch

回答

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 

enter image description here