vbacompiler-errorspowerpointadd-inreference-library

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


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!


Solution

  • 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