How to write the macro to turn off the hyperlink in word

L

Lillian

I have one users he copy some doucments from the web,
here is the link he copy from
http://www.treasurer.ca.gov/laif/ he would like turned
off all the underline hyperlink, I know I can right click
link and removed one by one, is any way someone can help
me write the macro to turned them off at once.

Thanks for all your help.

Lillian
 
J

Jonathan West

Hi Lillain

This will do the trick

Sub RemoveAllHyperlinks
Dim i as Long
With ActiveDocument.Range
For i = 1 to .Hyperlinks.Count
.Hyperlinks(1).Delete
Next i
End Sub

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
K

Klaus Linke

Lillian said:
I have one users he copy some doucments from the web,
here is the link he copy from
http://www.treasurer.ca.gov/laif/ he would like turned
off all the underline hyperlink, I know I can right click
link and removed one by one, is any way someone can
help me write the macro to turned them off at once.


Hi Lillian,

You probably don't need a macro.

If you want to keep the hyperlinks but remove the underline, edit the
"Hyperlink" character style so it doesn't have an underline.

If you want to remove the hyperlinks (= change them into plain text),
select everything and unlink fields (Ctrl+A, Ctrl+Shift+F9).

Regards,
Klaus
 
H

Helmut Weber

Hi Lilian,
your user doesn't need a macro.
[ctrl a] followed by [ctrl shift F9] should do the trick.
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT4.0
 
D

Dave Lett

Hi Jonathan,

Two things: first a type (change 1 to i). However, the hyperlinks collection
is one of those collections that you have to do in "reverse" order, as in
the following:

For iLink = oDoc.Hyperlinks.Count To 1 Step -1
oDoc.Hyperlinks(iLink).Delete
Next iLink

HTH
 
J

Jonathan West

Dave Lett said:
Hi Jonathan,

Two things: first a type (change 1 to i).

No, it *wasn't* a typo. Look carefully and step through the code to see what
it does...
However, the hyperlinks collection
is one of those collections that you have to do in "reverse" order, as in
the following:

For iLink = oDoc.Hyperlinks.Count To 1 Step -1
oDoc.Hyperlinks(iLink).Delete
Next iLink

If all you're doing is deleting the whole lot, then my way is marginally
quicker. If you might be wanting to selectively delete only certain links,
then yes, you would need to go backwards.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
D

Dave Lett

My apologies.

Jonathan West said:
No, it *wasn't* a typo. Look carefully and step through the code to see what
it does...


If all you're doing is deleting the whole lot, then my way is marginally
quicker. If you might be wanting to selectively delete only certain links,
then yes, you would need to go backwards.

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
J

JGM

Wow!

So simple, so effective, so brilliant!

How do you come up with stuff like that!

It would not have occurred me to use
For i = 1 to .Hyperlinks.Count
.Hyperlinks(1).Delete
Next i
so that after each iteration the value of .Hyperlinks.Count
goes down by one!
I would have come up with something very complicated that would have
involved selecting each hyperlink one by one...
I hope one day I can come up with stuff like that on my own!

Cheers!
 

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