WorksheetFunction.CountA(Range("A1:A"))
Private Function GetValue(path, file, sheet, ref)
' Retrieves a value from a closed workbook
Dim arg As String
' Make sure the file exists
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
' Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Address(, , xlR1C1)
' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function
Sub Main()
path = ActiveWorkbook.path
file = "countA.xlsx"
sheet = "Sheet1"
cell = "C2"
Range("B1").Value = GetValue(path, file, sheet, cell)
End Sub