Automating change link source in Word document

S

SchalkJ

I created a master Word document, which has 115 links to a master Excel file. For each new client of mine, I need to save both the Word document and the Excel file under new names. This means that I have to change the links source manually for all 115 links. This becomes a rather tedious task, as I add new clients daily.

Can someone help me with a macro that will change the link source? I use Word 2002 and Excel 2002.
 
H

Helmut Weber

Hi,
you got 115 links to one (1) Excel-File?
In case there are no other links,
that would be quite simple:
Dim oHpl As Hyperlink
For Each oHpl In ActiveDocument.Hyperlinks
oHpl.Address = "c:\test\another.xls"
next
If you want to change the text, that is displayed,
this would be:
oHpl.TextToDisplay = "MyText"
HTH
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
J

Jonathan West

SchalkJ said:
I created a master Word document, which has 115 links to a master Excel
file. For each new client of mine, I need to save both the Word document and
the Excel file under new names. This means that I have to change the links
source manually for all 115 links. This becomes a rather tedious task, as I
add new clients daily.
Can someone help me with a macro that will change the link source? I use
Word 2002 and Excel 2002.

Hi SchalkJ

You can iterate through the links in your document like this

Dim oField as Field
For each oField in ActiveDocument.Fields

'field-specific code goes here

Next oField

For the field-specific code, what you can do is read the Code property of
the field. If it is a link field, then you can change the link to the new
value by witing a replacement string into the Code property. Exactly what
you would need for this depends on what changes you want to make. You should
be able to take it from here.
 
H

Helmut Weber

Hi SchalkJ,
(a real name would be much nicer :),
I don't know, how much an expert you are.
Therefore, instead of creating a ready to use
solution for you, which might not be required,
here some hints:
As far as I got until now, these fields are
of type "wdFieldLink" = 56.
The field has a code property.
That property can overwritten.
I tested it like this:
Dim d as document
set d = activedocument
d.Fields(3).Code = d.Fields(2).Code
where these fields are of type wdFieldLink, of course
plus updating, of course again.
Let us now, if you need further help.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?U2NoYWxrSg==?=,
I created a master Word document, which has 115 links to a master Excel file. For each
new client of mine, I need to save both the Word document and the Excel file under new
names. This means that I have to change the links source manually for all 115 links. This
becomes a rather tedious task, as I add new clients daily.
Can someone help me with a macro that will change the link source? I use Word 2002 and Excel 2002.
Exactly how you can change these links depends on whether you've inserted the Excel stuff
"inline" with the text or as floating objects, with text wrap formatting?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply in the
newsgroup and not by e-mail :)
 
S

SchalkJ

Hi Cindy,
I inserted thelinks "inline", as part of the text, not as floating objects.
 

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