A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Microsoft Word Help
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

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



 
 
Thread Tools Display Modes
  #1  
Old May 31st 12, 12:16 PM
duffdeal duffdeal is offline
Junior Member
 
First recorded activity by WordBanter: May 2012
Posts: 0
Lightbulb Find all instances of a certain word and replace with hyperlink of same word

Hello

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'.

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

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

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

Cheers
Tom

Last edited by duffdeal : May 31st 12 at 12:23 PM. Reason: Missed out the hello
Ads
  #2  
Old May 31st 12, 04:17 PM posted to microsoft.public.word.docmanagement
Stefan Blom[_3_]
external usenet poster
 
Posts: 6,897
Default Find all instances of a certain word and replace with hyperlinkof same word

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

--
Stefan Blom
Microsoft Word MVP



On 2012-05-31 13:16 (GMT+1), duffdeal wrote:
Hello

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'.

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

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

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

Cheers
Tom




  #3  
Old May 31st 12, 04:21 PM posted to microsoft.public.word.docmanagement
Stefan Blom[_3_]
external usenet poster
 
Posts: 6,897
Default Find all instances of a certain word and replace with hyperlinkof same word

For more on macros, see http://www.gmayor.com/installing_macro.htm.

--
Stefan Blom
Microsoft Word MVP



On 2012-05-31 17:17 (GMT+1), Stefan Blom wrote:
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

  #4  
Old June 1st 12, 01:31 PM posted to microsoft.public.word.docmanagement
Suzanne S. Barnhill
external usenet poster
 
Posts: 33,626
Default Find all instances of a certain word and replace with hyperlink of same word

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

"duffdeal" wrote in message
...

Hello

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'.

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

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

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

Cheers
Tom




--
duffdeal


  #5  
Old June 2nd 12, 01:05 PM posted to microsoft.public.word.docmanagement
Lisa Wilke-Thissen
external usenet poster
 
Posts: 123
Default Find all instances of a certain word and replace with hyperlink of same word

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]

--
Cheers
Lisa [MS MVP Word]


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and highlight all instances of ALL CAPS ISay Microsoft Word Help 8 November 8th 09 01:00 PM
How to Find and Replace the Hyperlink Property of Text in Word 200 Ky Chapple Microsoft Word Help 3 June 10th 09 12:08 AM
Can I find all instances of a word and delete them at once? Cheryl Flanders Microsoft Word Help 0 February 3rd 09 01:48 AM
Can I find all instances of a word and delete them at once? Suzanne Microsoft Word Help 5 February 3rd 09 01:24 AM
How to replace all instances of a text string with a field referen Robert Kleinschmidt Microsoft Word Help 2 February 16th 05 12:34 AM


All times are GMT +1. The time now is 04:08 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright 2004-2020 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.