I am wondering how to define the specific file path to a cell location using Excel VBA? I am trying to load a value to nCount
which is the count in another file in a defined location. So more like assigning the value from a cell to nCount
.
nCount = "G:\ABC\[FILE FOR 2016-2017.xlsx]Master!$A$1"
It gives me an error:
Run-time error '13:"; "Type Mismatch
You can get a value from a closed workbook using and Excel4 macro. Here is a typical example:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.