为什么我的 VBA 项目在其他计算机上失败?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/613359/
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-11 10:15:54  来源:igfitidea点击:

Why does my VBA project fail in other computers?

excelms-accessvbaexcel-vba

提问by unigogo

I made a VBA project based on Excel and Access. When I copied to other computers, some methods (left, right, etc) or controls (ComboBox) sometimes disabled. I had to rebuild in that computer. But sometimes it's OK. Why? Is that because of licence issues?

我做了一个基于 Excel 和 Access 的 VBA 项目。当我复制到其他计算机时,有时会禁用某些方法(左、右等)或控件(ComboBox)。我不得不在那台电脑上重建。但有时也没关系。为什么?那是因为许可证问题吗?

回答by RedBlueThing

Check the references on the computer that it is failing on (via tools/references menu item in the VBA editor). Different platforms can have different sets of DLLs installed and you will get some misleading errors from excel if there is a reference that is marked "MISSING".

检查出现故障的计算机上的引用(通过 VBA 编辑器中的工具/引用菜单项)。不同的平台可以安装不同的 DLL 集,如果存在标记为“MISSING”的引用,您会从 excel 中得到一些误导性错误。

This is discussed in this question

在这个问题中讨论

回答by Will Rickards

This is a version difference/missing reference issue. Sometimes it gives you the error on the correct function, and sometimes on completely unrelated functions.

这是版本差异/缺少参考问题。有时它会给你正确函数的错误,有时是完全不相关的函数。

If you are deploying to different versions of Excel you can use late binding instead of early binding to relieve this problem. When you are developing you can use stuff like

如果您要部署到不同版本的 Excel,则可以使用后期绑定代替早期绑定来缓解此问题。在开发时,您可以使用类似的东西

Dim x As Excel.Application
x = New Excel.Application

But for deployment you can change it to the following and then remove the reference altogether.

但是对于部署,您可以将其更改为以下内容,然后完全删除引用。

Dim x As Object
x = CreateObject("Excel.Application")

回答by Fionnuala

It is important to check security and permissions on the computer that you are having problems on. Users must have full permissions on both the fron-end and back-end folders. Macros will not run if security settings do not permit them. You may wish to read:

检查您遇到问题的计算机的安全性和权限非常重要。用户必须对前端和后端文件夹具有完全权限。如果安全设置不允许,宏将不会运行。您可能希望阅读:

Self certification and digital signatures

自我认证和数字签名

General information on security principals for Office code and macro security

Office 代码和宏安全的安全主体的一般信息

Trusted location defaults for Office 2003

Office 2003 的受信任位置默认值

Macro security in Office 2003

Office 2003 中的宏安全

For the most part, late binding will solve problems with references in VBA, unless you have some unusual references. Most problems are caused by differences in library versions that can be overcome with late binding. With VBA, it is often recommended that you develop with early binding but release with late binding. The main disadvantage of late binding is changing built-in constants to values (speed is no longer the issue it used to be.)

在大多数情况下,后期绑定将解决 VBA 中的引用问题,除非您有一些不寻常的引用。大多数问题是由库版本的差异引起的,可以通过后期绑定来克服。使用 VBA,通常建议您使用早期绑定进行开发,但使用后期绑定进行发布。后期绑定的主要缺点是将内置常量更改为值(速度不再是以前的问题。)

回答by Codex73

Not because on licensing. A lot of factors could be, but I could nail it down to: Depending on the Office SP version differences on multiple computers, it might give you headaches. Also check the Office Web Components version of each. Your Options & Add-in on Office might give you some clues.

不是因为许可。可能有很多因素,但我可以将其归结为: 根据多台计算机上的 Office SP 版本差异,它可能会让您头疼。还要检查每个的 Office Web Components 版本。Office 上的选项和加载项可能会给您一些线索。