避免“找不到项目或库”在没有安装应用程序的电脑 [英] Avoiding "Can't find project or library" on computer without app installed

查看:122
本文介绍了避免“找不到项目或库”在没有安装应用程序的电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Excel文件,其中包含一个引用Powerpoint的模块。



我想在没有安装Powerpoint的服务器上使用这个文件中的其他模块(长篇故事...),但不会导致可怕的找不到项目或库错误信息。



当然,我可以简单地创建另一个版本,并将违规模块删除,这显然工作正常。

但是,有几个原因我不想这样做,尤其是我真的不想要维护多个版本,如果我可以帮助它。



有没有办法呢?让Excel忽略这个模块,而不是尝试编译它,除非它被调用?



我已经在这个主题上对41个帖子进行了翻译,没有找到任何有帮助的东西,这让我怀疑我是不可能的。



有一些建议,晚期绑定可能有帮助,但似乎没有任何区别。以下是违规代码:

  Dim PowerPointApp As Object 
On Error Resume Next
设置PowerPointApp = GetObject (class:=PowerPoint.Application)
Err.Clear
如果PowerPointApp不是,然后
设置PowerPointApp = CreateObject(class:=PowerPoint.Application)
结束If
On Error GoTo 0

其他模块都没有引用Powerpoint。 p>

解决方案


有没有办法呢,例如让Excel忽略这个模块,而不是尝试编译它,除非它被调用?


你可以尝试条件编译,这几乎完全是它的作用。



打开项目属性对话框,并定义一个项目级别条件编译常数:



现在使用 #If 指令包装PowerPoint依赖模块:

  Option Explicit 
#如果HAS_POWERPOINT = 1然后
'...整个模块体...
#End如果

然后,无处不在,你有一段代码调用有条件编译的模块,用#如果指令:

 #如果HAS_POWERPOINT = 1然后
MyProcedureThatRunsOffPowerPointfoo ,bar,42
#Else
'依赖PowerPoint的模块不存在,我们该怎么办?
#End如果

现在,当您将宏分发到没有PowerPoint安装后,您转到项目属性并将常量设置为0,然后重新编译项目。


I have created an Excel file which contains one module which refers to Powerpoint.

I want to use the other modules in this file on a server which does not have Powerpoint installed (long story...), but cannot do this without incurring the dreaded Can't find project or library error message.

Of course I can simply create another version with the offending module deleted, which obviously works fine.
However, there are several reasons why I don't want to do this, not least that I really don't want to have to maintain multiple versions if I can help it.

Is there any way around this, e.g. getting Excel to ignore this module and not try to compile it unless it is called?

I have waded through 41 posts on stackoverflow on this topic, without finding anything that helps, which makes me suspect that I am asking the impossible.

There are some suggestions that late binding might help, but it does not seem to make any difference. Here is the offending code:

Dim PowerPointApp As Object
On Error Resume Next
  Set PowerPointApp = GetObject(class:="PowerPoint.Application")
  Err.Clear
  If PowerPointApp Is Nothing Then
    Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
  End If
On Error GoTo 0

None of the other modules make any reference to Powerpoint.

解决方案

Is there any way around this, e.g. getting Excel to ignore this module and not try to compile it unless it is called?

You could try conditional compilation, that's pretty much exactly what it does.

Open up the project properties dialog, and define a project-level conditional compilation constant:

Now wrap the PowerPoint-dependent module with #If directives:

Option Explicit
#If HAS_POWERPOINT = 1 Then
'... entire module body ...
#End If

Then, everywhere you have a piece of code that calls into the conditionally-compiled module, surround it with #If directives:

#If HAS_POWERPOINT = 1 Then
    MyProcedureThatRunsOffPowerPoint "foo", "bar", 42
#Else
    'PowerPoint-dependent module doesn't exist, what do we do instead?
#End If

Now when you distribute the macro to the machine that doesn't have PowerPoint installed, you go to project properties and set the constant to 0, then recompile the project.

这篇关于避免“找不到项目或库”在没有安装应用程序的电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆