Public Function GetCellValue(strPath, strFile, strSheet, strA1)
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
If Dir(strPath & strFile) = "" Then '判断文件是否存在
'文件不存在时产生运行时错误,此错误会传递给调用此函数的过程
Err.Raise 12345, "GetCellValue", "No found file"
Exit Function
End If
'调用XLM4.0宏表函数读取指定区域的内容
'如果指定工作表不存在,返回错误
GetCellValue = ExecuteExcel4Macro("'" & strPath & "[" & strFile & "]" _
& strSheet & "'!" & Range(strA1).Address(, , xlR1C1))
End Function
Excel VBA 不打开Excel文件访问其中内容的方法
最新推荐文章于 2025-04-17 17:57:51 发布
本文介绍了如何使用VBA的XLM4.0宏表函数来从Excel工作簿中获取特定工作表上的单元格值,并处理文件不存在时的异常情况。

723

被折叠的 条评论
为什么被折叠?



