VBA add-in: how to “embed” the required reference libraries? Getting “Compile error in hidden module” when sending functional add-in to other users

眉间皱痕 提交于 2019-12-24 06:45:19

问题


I wrote a powerpoint add-in that works well on my local computer. Yet when I email the file to others, all of a sudden half the functionalities no longer work and show the compile error as listed in the subject line.

Digging a bit deeper, it appears the issue is that the client computers do not have the correct reference libraries (e.g., Excel 14.0 Object Library, Outlook, Access, etc.). I have these libraries correctly referenced when writing the add-in as a pptm file, but imagine that when I saved the pptm into a ppam file, the reference libraries were "lost" somehow.

Does anyone have any ideas? Note that adding the reference libraries directly on the client computers does not appear to help. Instead, I'd need to send the client the foundational pptm file, add the reference libraries, then save that file as a ppam file on the client computer directly, which of course is not practical. So how does one "embed" reference libraries to the add-in?

Thank you!


回答1:


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

You don't.

Alternative:

Instead of Early binding, use Late Binding.

Example code of Early Binding.

Here we set a reference to MS Word xx.xx Object Library.

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

Converting the above to Late Binding.

Here we do not set the reference but let the code bind to whatever version of MS Word is present in the destination pc.

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

Similarly you can change your code for MS-Excel as well.

For Further Reading



来源:https://stackoverflow.com/questions/20463514/vba-add-in-how-to-embed-the-required-reference-libraries-getting-compile-er

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!