VBA 参考库

发布于 2024-07-11 20:31:28 字数 298 浏览 6 评论 0原文

我是 VBA 新手,一直在为 Office 编写一个小型宏应用程序。 我们有大约 80 个用户,他们的电脑设置基本相同,除了少数用户之外,所有用户都可以访问它。

我一直在尝试使用 Web 服务引用来自动访问网页,并且我还将 Microsoft 脚本运行时引用加载到项目中。 我尝试在测试 PC 上运行它,但它抱怨缺少引用。

我并不是特别想使用 80 台 PC 并手动加载参考资料。

我的问题基本上是,我应该如何管理这个宏应用程序向 80 个以上用户的分发,以确保每次为每个用户加载引用。

谢谢!

I'm new to VBA and have been throwing together a small macro application for the Office. We've got about 80 users on essentially identical PC setups, and it will be accessed by all but a few users.

I've been playing around with some automation of accessing web pages using the Web Services references, and I've also loaded the Microsoft Scripting Runtime references into the project. I attempted to run it on a test PC and it complained that there were missing references.

I don't particularly want to go around 80 PCs and manually load the references.

My question, basically, is how should I manage the distribution of this macro-app to 80 odd users so as to ensure that the references will load every time for every user.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深海蓝天 2024-07-18 20:31:28

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

所以:

Dim fs As Object 'Instead of FileSystemObject '
Dim xl As Object 'Instead of Excel.Application '

Set fs=CreateObject("Scripting.FileSystemObject")
Set xl=CreateObject("Excel.Application")

'Value instead of built-in constant '
ForReading=2
Set f = fs.OpenTextFile("c:\testfile.txt", ForReading)

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.)

So:

Dim fs As Object 'Instead of FileSystemObject '
Dim xl As Object 'Instead of Excel.Application '

Set fs=CreateObject("Scripting.FileSystemObject")
Set xl=CreateObject("Excel.Application")

'Value instead of built-in constant '
ForReading=2
Set f = fs.OpenTextFile("c:\testfile.txt", ForReading)
饮湿 2024-07-18 20:31:28

如果您有应用程序所依赖的引用,并且您知道这些引用不会出现在目标 PC 上,那么我强烈建议您研究一些安装程序技术。

使用安装程序,您应该能够安装宏,并安装和注册所有适当的引用/库。

Windows 上通常有两种风格:基于 Windows Installer 的技术和基于脚本的技术。

尽管有多种选项可供您使用(Stack Overflow 上有一些讨论),但我们的所有部署都使用 InstallShield。

使用 Windows 安装程序技术,您可以构建 MSI 安装文件,然后可以使用组策略自动部署该文件。

If you have references that your application depends on, that you know are not going to be on the target PCs, then I would strongly recommend you investigate some installer technology.

Using the installer you should be able to install your macro, and install and register all appropriate references / libraries.

There are generally two flavours on windows, Windows Installer based technology and Script based technology.

We use InstallShield for all of our deployment, although there are several options for you to use (there are several discussion on Stack Overflow).

Using windows installer technology, you can build MSI install files, which you are then able to deploy automatically using Group Policy.

九命猫 2024-07-18 20:31:28

不要让文档公开功能,而是将其作为 Office 的加载项(套件或单个应用程序,由您选择)。 这样,您就不必处理引用。

然后,只需分发包含加载项的安装包,该加载项会注册组件并将加载项注册到适当的 Office 应用程序。

VB6 在这里可能是一个好主意,因为它与 VBA 相似。

Instead of having the documents expose the functionality, make it an add-in for Office (the suite, or the individual apps, your choice). This way, you don't have to deal with references.

Then, just distribute an install package with the add-in which registers the components and registers the add-ins with the appropriate Office apps.

VB6 might be a good idea here, given it's similarity to VBA.

彻夜缠绵 2024-07-18 20:31:28

除了这个答案(这是解决此类问题的防弹解决方案)之外,但实现起来相当复杂,您还可以编写一些在 VBA 应用程序启动时执行的代码,检查“应用程序”对象的“引用”集合。 然后,您可以检查 (1) 计算机上是否提供请求的文件(dll、ocx、tlb),以及 (2) 是否可以创建引用 (application.references.addFromFile ...)。

请注意:可能是“引用相关”的对象声明,例如:

Dim cat as ADOX.catalog 

如果“编译”相应模块时引用未处于活动状态,则会引发编译错误。 然后,我建议您将“引用检查过程”隔离在启动模块(相当于“自动执行”)中,该模块仅处理 VBA 和基本应用程序对象。 使用帮助文件进行检查(例如:在 Access 中,无需外部引用即可使用的默认引用是 VBA、Access 和 DAO)。

编辑:

如果外部引用依赖于其他软件包并且(1)无法与 MSI 文件一起分发或(2)可以有多个版本,我认为“references.addFromFile”是唯一可以应用的解决方案。 示例:

  • 您有一个 VBA/Access 运行时客户端
    需要引用Word的应用程序
    (msword.olb 文件)。
  • 对于许可问题,您不能随您的 msi 包自由分发此文件
  • 。olb 文件可以是“XP 版本或较新的版本”。

我们的解决方案是在客户端访问文件上有 2 个表。 一个列出了在启动时必须检查或添加的所有引用(Word 将是其中之一),另一个列出了文件的所有可能位置(取决于用户是否有“office11”版本或更新版本) 1),两个表之间具有一对多关系。

因此,最好的策略可能是 msi 包和通过代码进行管理的混合:

  • msi 非常适合分发独立的 dll 或完全“嵌入”到您的应用程序中的其他文件,例如 activeX 控件(如扫描仪控件、报告或文件查看器)等)
  • 代码是最佳解决方案,您的应用程序必须与用户计算机上不同版本中存在的其他应用程序(word、excel、outlook 等)进行通信。

In addition to this answer, which is the bullet-proof solution to solve this kind of issue, but which is quite complex to implement, you can also write some code to be executed when your VBA application starts, checking the 'references' collection of the 'application' object. You can then check (1) if requested files (dll, ocx, tlb) are available on the computer and (2) if reference can be created (application.references.addFromFile ...).

Be careful: object declarations that might be 'reference dependent', such as:

Dim cat as ADOX.catalog 

will raise a compilation bug if the reference is not active when the corresponding module is 'compiled'. I then advise you to isolate your 'reference checking procedure' in a startup module (equivalent to an 'autoexec') which deals only with VBA and basic application objects. Check it with your Help Files (Example: in Access, default references that can be used without external references are VBA, Access and DAO).

EDIT:

in case external references depend on other software package and (1) cannot be distributed with a MSI file or (2) can have multiple versions, I think the 'references.addFromFile' is the only solution that can apply. Example:

  • You have an VBA/Access runtime client
    app that needs to refer to Word
    (msword.olb file).
  • For licensing issues, you cannot freely distribute this file with your msi pack
  • the olb file can be either the 'XP version or a newer one

Our solution is to have 2 tables on the client Access file. One lists all the references that have to be checked or added at startup time (Word will be one of them), and the other one lists all the possible locations of the file (depending if the user has the 'office11' version or a newer one), with a one to many relations between the 2 tables.

So, the best strategy could be a mix between msi packs and management through code:

  • msi is great for distributing independant dll's or other files that are totally 'embedded' in your app, such as activeX controls (like scanners controls, report or file viewers, etc)
  • code is the best solution where your app will have to communicate with other applications (word, excel, outlook, etc) that can exist in different versions on your user's machines.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文