Setting References Programmatically

Setting References Programmatically

Anonymous
Not applicable
389 Views
5 Replies
Message 1 of 6

Setting References Programmatically

Anonymous
Not applicable
I've read in several posts that you can set references programmatically. I have created and incorporated a scripting dictionary in my first ever VBA routine. Of course I had to check the Microsoft Scripting Runtime in References to create it, and it looks like my end users will have to do the same. So I'd like for the program to do it without user intervention.

In a really old post, Joe Sutphin showed how to create an AddReference function but prefaced it by saying "You must set a reference to 'Microsoft Visual Basic Extensibility 5.3' for this to work. So, for my purposes, it looks like I might as well just go to each machine and reference Microsoft Scripting Runtime and forget trying to do it programmatically. Have I misunderstood something?
0 Likes
390 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Hi,

When you add a reference to a VBA project, the reference is stored in the
DVB and you can readily copy the DVB file to another computer and it will
work - provided the referenced object is available on the other computer.
As the Scripting Object is installed with Windows, you can feel reasonably
comfortable using it.

--

Laurie Comerford
CADApps
www.cadapps.com.au
www.civil3Dtools.com
wrote in message news:5465418@discussion.autodesk.com...
I've read in several posts that you can set references programmatically. I
have created and incorporated a scripting dictionary in my first ever VBA
routine. Of course I had to check the Microsoft Scripting Runtime in
References to create it, and it looks like my end users will have to do the
same. So I'd like for the program to do it without user intervention.

In a really old post, Joe Sutphin showed how to create an AddReference
function but prefaced it by saying "You must set a reference to 'Microsoft
Visual Basic Extensibility 5.3' for this to work. So, for my purposes, it
looks like I might as well just go to each machine and reference Microsoft
Scripting Runtime and forget trying to do it programmatically. Have I
misunderstood something?
0 Likes
Message 3 of 6

Anonymous
Not applicable
Thank you,

Your assurance about the references being saved in the DVB led me to believe something was wrong with the way I was testing the code. It works now. Even though I had saved the DVB, I hadn't unloaded then reloaded it before trying to test it. Does that make sense?
0 Likes
Message 4 of 6

Anonymous
Not applicable
Hi Laurie

Yes you are right the references are in dvb, but not all references are available on all the machines because of the the program runs in one system and gives error in another system.To solve this one has to go to VBAIDE open references menu and set the path for the missing one.
This procedure can be carried out easily by a VBA programmer but not by ordinary user.

So to solve this problem what i thought was to copy all references files (.dll .ocx or whaterver) and put in a directory along with the .dvb files so that the VBA programs and its depending files can be circulated easily.

But to work it we have to write a code so that every time you run it automatically adds references from the directory which we specify.


I tried this code but its not working.

Sub ADDRef()
Dim NewRef as References

Set NewRef =New References

NewRef.Addfromfile ("C:\Myprogram\refedit.dll")

End sub

I think some modification is required for this program. can you help me.
Thanks
Benny
0 Likes
Message 5 of 6

Anonymous
Not applicable
Hi Benny,

When you use ActiveX programming (such as VB or VBA), you should use Windows
to register the DLLs, OCXs etc. In the VBA References you then select the
reference from the list. DO NOT BROWSE and select a file. If the file you
are trying to link with is not visible in the list, you should then
register*** it to make it available.

That way the the DVB uses the Windows environment to find the file and does
not rely on the user doing what you describe. This is how all commercial
developers distribute their password protected files where in the user has
no access to the code to change references.

If you have a custom DLL, then it should be copied with the VBA program and
registered in its new location.

This is why you need an installation program like "Inno Setup" for such
program distribution.
Also, You need an understanding of the DLLs - are they yours and were
developed in conjunction with your DVB, or are the commercial DLLs, or
Window's ones? Each should be handled differently. Only the first type can
reasonably be placed in the directory with your DVB.
--

*** Type Regsvr32 in the Windows Run Box, then use Windows Explorer to drag
your file into the box and press enter.

Laurie Comerford
CADApps
www.cadapps.com.au
www.civil3Dtools.com

wrote in message news:5466342@discussion.autodesk.com...
Hi Laurie

Yes you are right the references are in dvb, but not all references are
available on all the machines because of the the program runs in one system
and gives error in another system.To solve this one has to go to VBAIDE open
references menu and set the path for the missing one.
This procedure can be carried out easily by a VBA programmer but not by
ordinary user.

So to solve this problem what i thought was to copy all references files
(.dll .ocx or whaterver) and put in a directory along with the .dvb files so
that the VBA programs and its depending files can be circulated easily.

But to work it we have to write a code so that every time you run it
automatically adds references from the directory which we specify.


I tried this code but its not working.

Sub ADDRef()
Dim NewRef as References

Set NewRef =New References

NewRef.Addfromfile ("C:\Myprogram\refedit.dll")

End sub

I think some modification is required for this program. can you help me.
Thanks
Benny
0 Likes
Message 6 of 6

Anonymous
Not applicable
Hi Laurie

Thank you very much for your information ....I need to work on that..
0 Likes