VBA 加载项 : how to "embed" the required reference libraries? 向其他用户发送功能加载项时获取 "Compile error in hidden module"

标签 vba compiler-errors powerpoint add-in reference-library

我编写了一个在我的本地计算机上运行良好的 powerpoint 插件。然而,当我将文件通过电子邮件发送给其他人时,突然一半的功能不再起作用,并显示主题行中列出的编译错误。

再深入一点,问题似乎是客户端计算机没有正确的引用库(例如,Excel 14.0 对象库、Outlook、Access 等)。在将加载项编写为 pptm 文件时,我正确引用了这些库,但想象一下,当我将 pptm 保存到 ppam 文件中时,引用库不知何故“丢失”了。

有没有人有任何想法?请注意,直接在客户端计算机上添加引用库似乎没有帮助。相反,我需要向客户端发送基础 pptm 文件,添加引用库,然后将该文件作为 ppam 文件直接保存在客户端计算机上,这当然是不切实际的。那么如何将引用库“嵌入”到插件中呢?

谢谢!

最佳答案

So how does one "embed" reference libraries to the add-in?



你没有。

备选 :

使用后期绑定(bind)代替早期绑定(bind)。

早期绑定(bind)的示例代码。

这里我们设置了对 MS Word xx.xx 对象库的引用。
Sub Sample()
    Dim oWrd As Word.Application
    Dim oDoc As Word.Document

    Set oWrd = New Word.Application

    Set oDoc = oWrd.Documents.Open("....")

    '
    '~~> Rest of the code
    '
End Sub

将上述转换为后期绑定(bind)。

在这里,我们不设置引用,而是让代码绑定(bind)到目标 PC 中存在的任何版本的 MS Word。
Sub Sample()
    Dim oWrd As Object
    Dim oDoc As Object

    Set oWrd = CreateObject("Word.Application")

    Set oDoc = oWrd.Documents.Open("....")

    '
    '~~> Rest of the code
    '
End Sub

同样,您也可以更改 MS-Excel 的代码。

For Further Reading

关于VBA 加载项 : how to "embed" the required reference libraries? 向其他用户发送功能加载项时获取 "Compile error in hidden module",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20463514/

相关文章:

vba - 如何使用 vba 将 yyyymm 数字字符串转换为月底日期?

vba - MS Word 中的链接表

vba - 从 Excel VBA 检查 Internet 连接

excel - 对象项不支持此属性或方法

java - 读取 .pptx 导致 java.lang.ClassNotFoundException

excel - 使用 msoFileDialogFilePicker 保存

c++ - 看到 std::vector<Typo> 和 std::vector<struct Typo> 时发出的编译器诊断之间存在差异的原因是什么

gcc - Riscv GCC 4.9.2无法编译linux 3.14.29

python - Pywin32 --> COM -->Powerpoint 教程?

excel - 代码中引用的 Excel 工作簿在任务栏中无处可见