Find all instances of a certain word and replace with hyperlink of same word

D

duffdeal

Hello

I would like a macro or method to find and replace instance of a word i
a large word document with a hyperlink who's display text is the same a
the original word.

Example: I would search for 'project' and replace all instances with
hyperlink www.example.com with the display text remaining 'project'.

I have found many macros that are tantalisingly close but not quite wha
I need. For example, a macro from another site will change all th
hyperlink addresses in a document and their display text.

I thought I could change all the instances of 'project' to a hyperlin
using inbuilt find and replace, then use that macro to change th
display text. However, the inbuilt find and replace function does no
create hyperlinks, you have to move the cursor to the unlinked text an
press space/enter to activate it. That's not viable in a larg
document.

To be really persnickety, it would be amazing if it only changed norma
body text rather than all text, so I could leave headings and header
unchanged. I imagine this is possible by using the inbuilt find an
replace to replace only normal text, then a macro to add the hyperlinks
perhaps.

Cheers
To
 
S

Stefan Blom

One possibility is to loop all hyperlink objects in a document and set
the address depending on the display text:

Dim h As Hyperlink
For Each h In ActiveDocument.Hyperlinks
If h.TextToDisplay = "project" Then
h.Address = "http://word.mvps.org"
End If
Next h
 
S

Suzanne S. Barnhill

Although Stefan's macro is doubtless more efficient, you can certainly
replace a word with a working URL. You just have to run AutoFormat over the
text (with all options other than "Internet and network paths with
hyperlinks" disabled) to convert the URLs to hyperlinks. Once you've done
that, you can replace the URLs with the display text (the underlying
hyperlink will not be changed).

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
L

Lisa Wilke-Thissen

Hi Tom,

"duffdeal" wrote
I would like a macro or method to find and replace instance of
a word in a large word document with a hyperlink who's display
text is the same as the original word.
Example: I would search for 'project' and replace all instances
with a hyperlink www.example.com with the display text remaining
'project'.

1. create a hyperlink (Ctrl+K ...) you need,
2. select, and copy the hyperlink (Ctrl+C),
3. Ctrl + H:
Find what: [your word, e. g. project]
Replace with: ^c [= content of clipboard]
 

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