2016-10-04 164 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

相關問題