获取值时,“错误2023”与“ExecuteExcel4Macro”

我用VBA维护一个Excel工作簿。

使用“ExecuteExcel4Macro”从已closures的Excel工作簿中获取值时,VBA失败。

从中获取值的工作簿保存在Intranet网页上。

GetValue = ExecuteExcel4Macro(arg) 

这行代码失败。 “错误2023”返回。

通过修改我发现的代码:

 tmp = GetValue(path, file, sheet, ref) ' tmp gets the "Error 2023"-return. Debug.Print tmp ' Gets the expected data-value from the excel-sheet. Datum_Homepage = GetValue(path, file, sheet, ref) 

如果两次调用它,第一次调用获得“错误2023”,第二次调用获得期望值(date)。

这怎么可能?

GetValue函数的完整代码:

 Public Function GetValue(path, file, sheet, ref) As Variant Dim arg As String If Right(path, 1) <> "/" Then path = path & "/" arg = "'" & path & "[" & file & "]" & sheet & "'!" & Range(ref).Address(, , xlR1C1) GetValue = ExecuteExcel4Macro(arg) End Function