VBA reference library

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

dan.solverud@gov.se
Posts: 5
Joined: Fri Oct 03, 2014 4:13 am

VBA reference library

Postby dan.solverud@gov.se » Mon Oct 06, 2014 5:15 am

Since not all users on the office LAN have EViews installed I need to use VBA to activate and deactivate the EViews 8.0 Type Library. While the activation goes splendid, the deactivation of the reference library is failing. To activate I use the command

vbProj.References.AddFromFile "C:\Program Files (x86)\EViews 8\x64\EViewsMgr.dll\1"

But the corresponding reference will not work in the deactivation command, i.e.:

vbProj.References.Remove "C:\Program Files (x86)\EViews 8\x64\EViewsMgr.dll\1"

How should I refer to the EViews 8.0 Type Library in the deactivation command?

EViews Steve
EViews Developer
Posts: 844
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: VBA reference library

Postby EViews Steve » Mon Oct 06, 2014 8:01 am

I had no idea you could even do this dynamically. You have to allow trusted access to VBA project object model under "Macro Settings" for this to even work. I had to google the Remove method. It doesn't take a string path to the dll -- it takes a Reference object. The following code sample works on my machine...

Code: Select all

Public Sub test() On Error GoTo ErrorHandler Dim ref Set ref = Application.VBE.ActiveVBProject.References.AddFromFile("C:\Program Files\EViews 8\EViewsMgr.dll") MsgBox "reference added" Application.VBE.ActiveVBProject.References.Remove ref MsgBox "reference removed" ExitHandler: Exit Sub ErrorHandler: MsgBox Err.Description, vbOKOnly, "Error" Resume ExitHandler End Sub

dan.solverud@gov.se
Posts: 5
Joined: Fri Oct 03, 2014 4:13 am

Re: VBA reference library

Postby dan.solverud@gov.se » Mon Oct 06, 2014 10:18 am

Thank you, your code sample works on my machine as well. I tried to solve the tasks (adding and removing) in different sub's, which I could not get to work, but if I follow your example to put both the adding and the removing command in the same sub it works just fine.

administrator
Site Admin
Posts: 1
Joined: Tue Sep 16, 2008 2:22 pm

Re: VBA reference library

Postby administrator » Mon Oct 06, 2014 10:58 am

You can place the "ref" variable outside the method so it will be available for different methods.

Or, on exit, you can loop thru all references and see if any match the one that says "EViews 8.0 Type Library". Once found, you can remove that one.

Steve


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest