Setting a reference to a template in VBA

J

Janice

Hi All,

I want to write a program in VBA that remove broken references to documents
and then re establishes the reference. This is needed because the template
has changed name and moved to another server.

The code below does remove the broken reference. It even adds the
reference, but it does not work!

<SNIP>
For Each refTest In prjProj.References
If refTest.IsBroken Then prjProj.References.Remove refTest
Next refTest

ActiveDocument.VBProject.References.AddFromFile "C:\PO_TEMP.DOT"
</SNIP>

Documents based on the PO_TEMP.DOT should display a floating toolbar etc
when opened. However this is not displaying if I add the reference to the
existing documents.

A point to note is this. When I open the VBE with a document based on this
template, the project is not listed in the Projects tree. Then when going
into the References screen the project is allready selected so I exit and
then the project displays in the tree. However clicking on the project
gives an error "project is unviewable"

Can anybody possibly help me on this. I'm going a bit crazy!

Thanks

Janice Hardy
Support Officer
Hently and Hently Distributors
 
J

Janice

It may be pertinent to add I am using Word 2002.

Thanks

Janice Hardy
Support Officer
Hently and Hently Distributors
 
H

Heike Pertzel

Hallo Janice,

I've got also a problem with references which I've send to the 'microsoft.private.de.partner.office' newsgroup. But I did not receive any answer yet.Did you solve your problem? Could you please take a look at my problem?

Here is my problem:

I would like to remove a reference and paste it imediatly again with a macro in Word 2002.

This code works:

**********************************************

Dim x As Object

Set x = Application.VBE.ActiveVBProject _

..References.Item("Normal")

Application.VBE.ActiveVBProject.References.Remove x

**********************************************

This code DOES NOT work:

***************************************************

Dim x As Object

Set x = Application.VBE.ActiveVBProject _

..References.Item("Microsoft Shell Controls And Automation") Application.VBE.ActiveVBProject.References.Remove x

***************************************************

(it concerns C:\windows\system32\shell32.dll)

Do you know what am I doing wrong?

Many thanks

Heike Pertzel / DATA 5 GmbH
 
H

Heike Pertzel

The solution is:

Dim xx As Object
On Error Resume Next
Set xx = Application.VBE.ActiveVBProject.References.Item("Shell32")
Application.VBE.ActiveVBProject.References.Remove xx
On Error GoTo 0
Application.VBE.ActiveVBProject.References.AddFromFile ("C:\windows\system32\shell32.dll")

Heike Pertzel / DATA 5 GmbH


Hallo Janice,

I've got also a problem with references which I've send to the 'microsoft.private.de.partner.office' newsgroup. But I did not receive any answer yet.Did you solve your problem? Could you please take a look at my problem?

Here is my problem:

I would like to remove a reference and paste it imediatly again with a macro in Word 2002.

This code works:

**********************************************

Dim x As Object

Set x = Application.VBE.ActiveVBProject _

.References.Item("Normal")

Application.VBE.ActiveVBProject.References.Remove x

**********************************************

This code DOES NOT work:

***************************************************

Dim x As Object

Set x = Application.VBE.ActiveVBProject _

.References.Item("Microsoft Shell Controls And Automation") Application.VBE.ActiveVBProject.References.Remove x

***************************************************

(it concerns C:\windows\system32\shell32.dll)

Do you know what am I doing wrong?

Many thanks

Heike Pertzel / DATA 5 GmbH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top