Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retain library references in VBA/Excel between startups

Tags:

excel

vba

My problem seems very basic and I was surprised to not find an answer after searching. So I would like to keep my library references between startups of Excel but they seem to reset every time.

I am using dictionaries in my VBA code so I need Microsoft Scripting Runtime enabled. How do I keep this reference up? Or is there a way to force it through my VBA code? This would actually be the best solution as this tool is going to be used by a few other people in my organization.

Someone has a solution to this? Any help is greatly appreciated.

like image 959
aso im Avatar asked Jun 01 '18 08:06

aso im


1 Answers

With this question you're essentially getting into the topic of early binding vs. late binding.

I'm assuming what you're doing now is early binding, which means you are adding the reference manually from the tool bar.

To persist the reference I'd suggest going with the late binding route.

Add the following lines to your code:

Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")

From there you can access the dict object by doing dict.method/function.

I'm providing you a few examples below that should help you get the idea of how to utilize this:

dict.add key, value
dict.remove key
dict.count

Given you're already working with the dictionary you probablly have a general understanding. If you need to understand more of the built in methods/functions refer to the following documentation:

https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/x4k5wbx4(v%3dvs.84)

like image 89
Dylan L Avatar answered Sep 29 '22 23:09

Dylan L