简体   繁体   English

需要使用这些方法的项目中引用Excel 2007 vba加载项吗?

[英]Excel 2007 vba addin required to be referenced in projects that consume the methods?

I have an Excel 2007 addin (a workbook with macros saved as an addin) that seems to require other books to reference before they can call its methods. 我有一个Excel 2007外接程序(带有保存为外接程序的宏的工作簿),似乎需要其他书籍进行引用才能调用它们的方法。

Is this normal? 这正常吗? I thought public addin code could be called from anywhere? 我以为可以从任何地方调用公共插件代码?

Is there a way to have a method available to all workbooks that are opened without creating an explicit reference? 有没有一种方法可用于所有打开的工作簿,而无需创建显式引用?

I'm also putting ribbon customizations in the addin and want to make sure these will also work. 我还将功能区自定义项添加到插件中,并希望确保它们也能正常工作。

As far as I know you cannot directly call procedures or functions from other workbooks in VBA unless you use one of the following methods: 据我所知,除非使用以下方法之一,否则无法直接从VBA中的其他工作簿中调用过程或函数:

  • Add a reference to the addin which contains the procedure you wish to call 添加对addin的引用,其中包含您要调用的过程
  • Or, call the procedure using Application.Run() supplying the filename of the addin and procedure you wish to call whilst the addin is loaded , eg application.run("MYADDIN.XLA!MySubToRun"). 或者,使用Application.Run()调用过程,该过程提供加载项的文件名和加载加载项时要调用的过程,例如application.run(“ MYADDIN.XLA!MySubToRun”)。 It's important to note that you don't need the full path, only the filename. 重要的是要注意,您不需要完整的路径,只需要文件名。

You can however utilise functions in the addin in worksheet cell formulas in other workbooks whilst the addin is loaded. 但是,在加载外接程序时,您可以在其他工作簿的工作表单元格公式的外接程序中使用函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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