vba 我仅在某些 Excel 2010 版本中收到“编译错误:找不到项目或库”。很难测试这个

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11533494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 13:34:41  来源:igfitidea点击:

I am getting 'Compile error: Can't find project or library' in a only some Excel 2010 versions. Difficult to test this

excelvbaexcel-vbaerror-handlingcompilation

提问by ExcelForFreelancers

My customer is getting a Compile Error; Can't find project or Library on his version of Excel 2010, however i am not getting this on my version of 2010. How can i adjust this code so it will not appear. When the error appears in the following code the text "cell" in "For each cell in selection" is highlighted:

我的客户收到编译错误;在他的 Excel 2010 版本上找不到项目或库,但是我在我的 2010 版本上没有找到这个。我如何调整此代码使其不会出现。当以下代码中出现错误时,突出显示“对于选择中的每个单元格”中的文本“单元格”:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B" Then
Columns("D:CB").Select
Selection.EntireColumn.Hidden = False
Application.ScreenUpdating = False

Sheet17.Range("E48:CB48").Select

For Each cell In Selection
    If cell = 0 Then
       Range(cell.Address).EntireColumn.Hidden = True
    End If
Next

Application.ScreenUpdating = True
Sheet17.Range("b9").Select
End If

End Sub`

My customer is also reporting a bug in the following code with the word "Response" being highlighted. This, as well, is not an issue for me, on my version of Excel 2010. Any and all help is greatly appreciated.

我的客户还报告了以下代码中的错误,其中突出显示了“响应”一词。在我的 Excel 2010 版本上,这对我来说也不是问题。非常感谢任何和所有帮助。

If Sheet1.Range("E18") = 3 Then
Response = MsgBox("Reminder Emails have been set to be sent automatically at " &               Sheet1.Range("f18").Value & ", " & Sheet1.Range("Q4").Value & " day(s) before" & vbCrLf & "the scheduled appointment. Do you want to send reminder e-mails now anyway?", vbYesNo)
    If Response = vbNo Then
    Exit Sub
    End If
    End If

回答by Smandoli

In the VBA window, go to Tools --> Referencesand ensure the same libraries are toggled on for all computers. Also make sure all active libraries are in the same order top-to-bottom.

在 VBA 窗口中,转到Tools --> References并确保为所有计算机打开相同的库。还要确保所有活动库从上到下的顺序相同。

Many libraries "come standard" but one may need to be toggled on. Or, a library reference may need to be toggled offdue to a functional interference. A library may be altogether missing, but I doubt this is the case since it's a fairly standard suite and you aren't aware of having tinkered with it.

许多库“成为标准”,但可能需要打开一个。或者,由于功能干扰,可能需要关闭库引用。一个库可能完全丢失了,但我怀疑是不是这种情况,因为它是一个相当标准的套件,而且你没有意识到已经对它进行了修改。

This is a typical issue and usually not considered too great a burden on your distribution clientele. If it is, you can rework your code to use fewer references; or you may be able to load the needed libraries programmatically(but I haven't ever tried that).

这是一个典型的问题,通常不会被视为对您的分销客户造成太大的负担。如果是,您可以重新编写代码以使用更少的引用;或者您可以以编程方式加载所需的库(但我从未尝试过)。

I suggest you include Option Explicitat the top of all modules. This problem looks a bit like a failure to declare your variables; and I think that requirement can vary by setting. Option Explicitwill force all variables to be declared, which is beneficial in general and could cause all client installs to act the same.

我建议你包括Option Explicit在所有模块的顶部。这个问题看起来有点像你的变量声明失败;我认为该要求可能因设置而异。 Option Explicit将强制声明所有变量,这通常是有益的,并且可能导致所有客户端安装的行为相同。