Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

How to add or delete references programmatically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marceepoo - 14 Feb 2008 19:46 GMT
Is it possible to list, add and/or delete references (for word .dot files)
programmatically?
I'm referring to the references shown by: Tools, References

Is there vba code (or vbscript code) that I could use to list the references
in use?  or to list the references that would be available if I were to check
the box for the references in question?

Any examples and/or tips on where to search would be much appreciated.
thanks in advance,

                              marceepoo
Shauna Kelly - 16 Feb 2008 10:18 GMT
Hi

See http://www.cpearson.com/excel/vbe.aspx. That site is about Excel,
but the VBE is the same for Word and Excel.

Bear in mind that any programming of the VBE itself requires that Word
is set up to trust access to the Visual Basic Project at Tools > Options
> Security > Macro Security > Trusted Publishers. Few IT departments
would roll out Word like that, and most people would recommend that they
not do so. So you can write code to manipulate the VBE for yourself, but
it's generally neither practical not recommended to write code for
others.

If your problem is that you want to be sure that your project has the
appropriate references, then consider late binding:
Early vs. Late Binding
http://www.word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

> Is it possible to list, add and/or delete references (for word .dot
> files)
[quoted text clipped - 11 lines]
>
>                               marceepoo
Marceepoo - 16 Feb 2008 15:46 GMT
Thanks Shauna for the informative answer.  In my office, I create the .dot
files for placement in the users' Word-Startup folders.  I copy the .dot
files from my computer to the various workstations.  Sometimes some of the
references get lost, and sometimes I find strange references with ~ prefixes
that have to be removed.

Bottom line (in light of your very helpful feedback), wouldnt't a good
solution be to password protect access to the Visual Basic Project (assuming
that that's possible; is it?)?  Thus, a startup routine could automitically
check to see if the references are correct, and fix them if necessary.

Is this a harebrained idea?

thanks,
                                     marc

> Hi
>
[quoted text clipped - 34 lines]
> >
> >                               marceepoo
Shauna Kelly - 16 Feb 2008 21:59 GMT
Hi

No, it's not harebrained, but it's not practical, either<g>.

You can password protect the VB Project. Furthermore, you should do so.
If the code strikes a run-time error, and it's password protected, the
user gets an annoying, but not disastrous error message. If the code
strikes a run-time error, and it's not password protected, the user gets
a dialog box offering the user the opportunity to Debug. If the user
clicks that, they end up in your code, and very few people will know
where they are or how to get out of it. So yes, definitely
password-protect the project.

But password protection won't stop the references from breaking.

If you have references to other projects, the only practical way to
deploy your project is to use late binding.

If your project is very large, and late binding would make code
development and maintenance very difficult, then one way around it is to
have two .dot files. Put one in the Word Startup folder, and use only
late binding there. It should check whether it is able to create an
object of the required kind. If it passes the test, then that code can
load a second .dot (stored in a known location, but *not* in the Word
Startup folder). The second .dot file can have references to other
things, and it should work OK.

In practice, this will work if your references are to, eg, Excel or a
dll. It does not work so reliably if your references are to another .dot
file.

Hope this helps.

Shauna Kelly.  Microsoft MVP.
http://www.shaunakelly.com/word

> Thanks Shauna for the informative answer.  In my office, I create the
> .dot
[quoted text clipped - 62 lines]
>> >
>> >                               marceepoo
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.