Results 1 to 2 of 2
Thread: Word VBA References (Word 2000)
2003-06-17, 00:12 #1
- Join Date
- Nov 2001
- Thanked 0 Times in 0 Posts
Word VBA References (Word 2000)
I am about to distribute a Word template nationally. The template relies heavily on VB to do stuff. I've noticed that on some machines the templates falls over because the appropriate references in 'Tools > References' aren't selected.
How can I set them using VB so that when the template is used, all the correct references are selected?
Thanks for your help.
2003-06-17, 00:37 #2
- Join Date
- Mar 2002
- Thanked 30 Times in 30 Posts
Re: Word VBA References (Word 2000)
References are stored with a document/template, so if they don't work on a client's PC, there must be some kind of problem. Trying to set a reference in code may be a case of trying to pull yourself out of quicksand by your own hair.
If you set a reference to the Microsoft Visual Basic for Applications Extensibility library, you can use the References collection and the Reference object in code. The References collection has methods AddFromFile and AddFromGuid that can be used to set a reference. For example to set a reference to the Access 2000 Object Library:
Application.VBE.ActiveVBProject.References.AddFrom File "C:Program FilesMicrosoft OfficeOfficeMSACC.OLB"
The problem, of course, is whether a particular library has been installed at all on the user's PC, and if so, where. Moreover, the user will have to allow programmatic access to the Visual Basic project - this is forbidden by default.
You can check if a reference is invalid by checking its IsBroken property.