Excel VBA 不打开Excel文件访问其中内容的方法

来源:互联网 发布:麻将洗牌算法 编辑:程序博客网 时间:2024/05/17 02:17
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

0 0