hyperlinks

R

Richard

I have a large docx file that has hyperlinks in it. They link to a doc file.

How can I change all the existing links to have them connect to a html file?

Richard
 
D

Doug Robbins - Word MVP

Maybe something like the following will help:

' Macro created 26/10/01 by Doug Robbins to update links in a document
'
Dim alink As Field, linktype As Range, linkfile As Range
Dim linklocation As Range, i As Integer, j As Integer, linkcode As Range
Dim Message, Title, Default, Newfile
Dim counter As Integer


counter = 0
For Each alink In ActiveDocument.Fields
If alink.Type = wdFieldLink Then

Set linkcode = alink.Code
i = InStr(linkcode, Chr(34))
Set linktype = alink.Code
linktype.End = linktype.Start + i
j = InStr(Mid(linkcode, i + 1), Chr(34))
Set linklocation = alink.Code
linklocation.Start = linklocation.Start + i + j - 1
If counter = 0 Then
Set linkfile = alink.Code
linkfile.End = linkfile.Start + i + j - 1
linkfile.Start = linkfile.Start + i
Message = "Enter the modified path and filename following this
Format " & linkfile
Title = "Update Link"
Default = linkfile
Newfile = InputBox(Message, Title, Default)
End If
linkcode.Text = linktype & Newfile & linklocation
counter = counter + 1
End If
Next alink


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

Richard

I really appreciate your help, but my use of VBA is very, very limited.

The file names are NWT.docx & NWT Hyperlinks.doc I will make the new file
hyperlink.htm

If you could use these names, I guess I could run it?

Thanking you in advance...

Richard
 
R

Richard

Doug,

I thank you for your quick reply.

I ran you file. I didn't get a message, so I modified your file as follows:

linkfile.End = linkfile.Start + i + j - 1
linkfile.Start = linkfile.Start + i
Message = "Enter the modified path and filename following this "
Format " & linkfile"
Hyperlinks.htm
Title = "Update Link"
Default = linkfile

Sorry I probably didn't do it right.

It did change one hyperlink to refer to Hyperlinks.htm

Thanks Richard
 
R

Richard

Doug,

I also have other hyperlinks that I would like to keep. I only want to
change the ones that link to Hyperlinks.doc to refer instead to
Hyperlink.htm

Thanks,

Richard
 

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