[英]Compile error on Excel 2010, but not on Excel 2003
I can't explain what is wrong with this simple code. 我无法解释此简单代码有什么问题。 It works perfectly on Excel 2003, but in Excel 2010 it displays:
它可以在Excel 2003上完美运行,但在Excel 2010中显示:
Compile error: Sub of Function not defined.
编译错误:未定义功能子。
Can anyone explain why is there an error on Excel 2010? 谁能解释为什么Excel 2010出现错误?
Sub Test_File_Opened()
If IsFileOpen("D:\Test.xls") Then
MsgBox "File is open!"
Else
MsgBox "File is closed!"
End If
End Sub
The IsFileOpen
function is not present in your code, this is the only possible explanation. IsFileOpen
函数不存在于您的代码中,这是唯一可能的解释。 You must declare it somewhere in your VBA module. 您必须在VBA模块中的某个位置声明它。
Here are a couple of things to check : 这里有几件事要检查 :
IsFileOpen
is not a VBA built-in function. IsFileOpen
不是VBA内置函数。 It probably comes from this Microsoft page (as pointed out by rusk in a comment) and the code just has to be made available in your new Excel 2010 workbook eg pasted into a module. 它可能来自此Microsoft页面 (由rusk在评论中指出),并且该代码仅需要在新的Excel 2010工作簿中可用,例如粘贴到模块中。
Why was it available in your Excel 2003 workbook but in your 2010 workbook? 为什么在Excel 2003工作簿中但在2010工作簿中可用? Could be any of a range of things.
可能是各种各样的东西。 It's in another module the you didn't copy over to the new workbook.
在另一个模块中,您没有将其复制到新工作簿中。 It's in an add-in not made available in your current installation of Excel 2010. Etc. Etc. You don't give enough information to diagnose the problem properly, but the remedy is the same regardless, as indicated above.
它是当前当前安装的Excel 2010中未提供的加载项等。您没有提供足够的信息来正确诊断问题,但是如上所述,无论如何,补救措施是相同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.