VBA Declaring a library vs dynamically loading it

I'm creating an application in VBA that uses a reference from vbscript.dll

I'm trying to figure out the best way to load the library, and am having difficulty distinguishing between using a declare function (http://msdn.microsoft.com/en-us/library/aa716201(v=vs.60).aspx) or just dynamically adding it to the list of references (How to add a reference programmatically vba-Excel, part 2 of the top answer)

If anyone can clarify the difference in result between the two, and maybe some advantages of one, I would be very happy.

My Notes: I like the looks of a simple declare function, for one thing it's short and looks nice. For another, I like avoiding hard coded paths unless I know the files won't be found in different places. On the other hand, I really like the error handling in method 2.


Declare is (typically) used for calling stdcall-supported functions exported from Windows DLLs. The VB run-time takes care of calling LoadLibrary, GetProcAddress, etc. to locate and load the functions you've declared. Most of the Windows API is used this way from VB/VBA.

References are used for COM objects -- that is, libraries that define a type library and a COM interface.

It's rare for a library to support both. If what you have is a COM library (if it appears in the 'References' dialog), add a reference to it and instantiate it that way.

Need Your Help

Referencing code-behind properties on .aspx page?

.net asp.net vb.net code-behind

On a .aspx page, what is the best way to link a server control's property to a property of the page class (its code-behind)? The only way that I have read about is to use databinding:

How to implement a unique index on two columns in rails

ruby-on-rails activerecord

I have a table and I'm trying to add a unique index on two columns. Those columns are also indexed. So my question is if I just can remove the indexes who were just for one column or if I have to u...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.