简体   繁体   English

在Excel 2010上编译错误,但在Excel 2003上不编译

[英]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 : 这里有几件事要检查

  • Did you misspell the procedure name? 您拼错了程序名称吗?
  • Try to call a procedure from another project without explicitly adding a reference to that project in the References dialog box. 尝试从另一个项目调用过程,而无需在“引用”对话框中显式添加对该项目的引用。
  • Specify a procedure that is not visible to the calling procedure. 指定对调用过程不可见的过程。
  • Declare a Windows dynamic-link library (DLL) routine or Macintosh code-resource routine that is not in the specified library or code resource. 声明不在指定库或代码资源中的Windows动态链接库(DLL)例程或Macintosh代码资源例程。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM