How to add a reference programmatically

前端 未结 4 1812
-上瘾入骨i
-上瘾入骨i 2020-11-22 06:02

I\'ve written a program that runs and messages Skype with information when if finishes. I need to add a reference for Skype4COM.dll in order to

4条回答
  •  孤街浪徒
    2020-11-22 06:51

    There are two ways to add references using VBA. .AddFromGuid(Guid, Major, Minor) and .AddFromFile(Filename). Which one is best depends on what you are trying to add a reference to. I almost always use .AddFromFile because the things I am referencing are other Excel VBA Projects and they aren't in the Windows Registry.

    The example code you are showing will add a reference to the workbook the code is in. I generally don't see any point in doing that because 90% of the time, before you can add the reference, the code has already failed to compile because the reference is missing. (And if it didn't fail-to-compile, you are probably using late binding and you don't need to add a reference.)

    If you are having problems getting the code to run, there are two possible issues.

    1. In order to easily use the VBE's object model, you need to add a reference to Microsoft Visual Basic for Application Extensibility. (VBIDE)
    2. In order to run Excel VBA code that changes anything in a VBProject, you need to Trust access to the VBA Project Object Model. (In Excel 2010, it is located in the Trust Center - Macro Settings.)

    Aside from that, if you can be a little more clear on what your question is or what you are trying to do that isn't working, I could give a more specific answer.

提交回复
热议问题