deleting hyperlinks

R

Ric Barline

Is there any way to delete all hyperlinks in a Word X document? Right now I
am having to go through and manually delete them (i do this by placing the
cursor at the end of the link and then hitting the backspace key). My
document has hundreds of such links and this will take me a while. I have
toggles field codes but do not see any special characters that I could use in
a global replace. I have tried globally replacing the para style, but that does
not get rid of the hyperlink. Any ideas?
 
E

Elliott Roper

Ric Barline said:
Is there any way to delete all hyperlinks in a Word X document? Right now I
am having to go through and manually delete them (i do this by placing the
cursor at the end of the link and then hitting the backspace key). My
document has hundreds of such links and this will take me a while. I have
toggles field codes but do not see any special characters that I could use in
a global replace. I have tried globally replacing the para style, but that
does
not get rid of the hyperlink. Any ideas?

What are you trying to do? Delete all the link text or get rid of the
blue colour and underline?

I tried, and Word v.X does not behave as advertised. I cannot persuade
search and replace to simply change styles like it says in help :-
"Replace specific formatting". It deletes the hyperlink text when the
find string is empty and the style is set to hyperlink. That might be
just what you want.

If I were stuck with misbehaving find and replace and wanted merely to
make the link text the same style as surrounding text, I'd do a little
macro to find the hyperlink style text and then do a normal for style
before looking for the next blue thing.

Ask a bit more after trying something along those lines.
 
R

Ric Barline

Thanks for replying. You are confusing hypertext formatting with the
hypertext itself - two different things. What I am trying to do is to remove
the hyperlink from the text, but not the text itself. Making text a hyperlink is
more than just applying a blue underlined format - it's embedding field (like
a cross reference field) into the text. If you right-click on the text that it
hypertexted, you can toggle the field to see the URL to which it links, but in
order to remove the link I need to open the link (select Hyperlink/Edit
Hyperlink) and click the "Remove Hyperlink" button. What I want is a way to
globally remove all the hyperlinks in the document rather than having to
delete them one at a time. Replace doesn't seem to work since it does not
appear that a hyperlink is a attribute like a format, nor a special character
like a paragraph mark, tab, etc. But something tells me there is a trick way
of doing this - I just don't know what it is and can't find it in the on-line
help.
 
E

Elliott Roper

Ric Barline said:
Thanks for replying. You are confusing hypertext formatting with the
hypertext itself - two different things.
Ahh! Indeed I was, and indeed it is
What I am trying to do is to remove the hyperlink from the text, but
not the text itself. Making text a hyperlink is more than just
applying a blue underlined format - it's embedding field (like a
cross reference field) into the text. If you right-click on the text
that it hypertexted, you can toggle the field to see the URL to which
it links, but in order to remove the link I need to open the link
(select Hyperlink/Edit Hyperlink) and click the "Remove Hyperlink"
button. What I want is a way to globally remove all the hyperlinks in
the document rather than having to delete them one at a time. Replace
doesn't seem to work since it does not appear that a hyperlink is a
attribute like a format, nor a special character like a paragraph
mark, tab, etc. But something tells me there is a trick way of doing
this - I just don't know what it is and can't find it in the on-line
help.
OK, by way of apology for wasting your time, and not least because it
was interesting, here is the beginning of a useful macro.
It will find the next block of text with hyperlink style (I could not
think of a better way to search for one) and remove the hyperlink data
associated with the text

Sub Hyperlink_remover()
'
' Hyperlink_remover Macro
' Macro recorded 13-05-2004 by Elliott Roper
'
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Hyperlink")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Range.Hyperlinks(1).Delete
End Sub

It might interest you and others how I got that (Blind leading the
blind lesson follows) I simply recorded a macro following your
directions above.
In more detail. Tools->macro->record new macro
It brings up a panel asking whether it is to be invoked by toolbar or
or keyboard. Me, I *hate* toolbars, so assigned ctrl-opt-h to it and
presssed close. Then a little (grr) toolbar pops out looking like
micro-iPod. That's the macro recorder controller. It is already
recording.
So I go through the find->format->style (hyperlink) panel and find
next. The next hyperlink in the document is highlighted. OK, so I then
go through the insert->hyperlink->remove routine (the ctrl-click
(rightclick) seems to be disabled while recording a macro), and yep,
the hyperlink stuff is no longer with the selected text. Then I reach
for the macro controller stop button and its done. Now every time I hit
ctrl-opt-h, Word scampers off to the next hyperlink and de-fuses it.

It would not be too hard to make it loop over every hyperlink. If were
doing this for myself, I'd probably make two macros, one to find the
first hyperlink block and another to delete the selected link stuff and
find the next. That way I get a chance to review what I'm about to
wreck.

There. I found that fun. I hope it's useful. (You can cut the macro out
of this article and paste it into your macro collection.)
 
D

Dayo Mitchell

A Hyperlink is a field code. Select it, then hit Cmd-shift-F9 which unlinks
the field leaving it regular text. If you only have hyperlinks in your doc,
you can select all and hit cmd-shift-F9, but if you have other types of
fields, it will kill those too. In that case, cmd-Y for redo might save a
keystroke.

DM

PS. Your original post did suggest that you wanted to remove the text
itself:
Right now I
am having to go through and manually delete them (i do this by placing the
cursor at the end of the link and then hitting the backspace key).
Elliot was not so confused. :)
 
R

Ric Barline

Thanks for the hint on recording a macro, but someone else gave me the
answer I was looking for. Cmd-A and then Shift-Cmd-F9 did it. I also use
recorded macros for other things such as turning tect copies from a web
page into usable text by removing all the paragraph returns at the end of
each line.
 
R

Ric Barline

Thanks Dayo for the answer I was looking for. I wasn't aware that Shift-
Cmd-F9 would remove all fields in a document. It worked great, leaving the
text alone but removing the linking to external items.
 
J

John McGhie [MVP - Word]

Hi Ric:

Try this macro:

Sub DeleteHyperlinks()
For Each alink In ActiveDocument.Hyperlinks
alink.Delete
Next alink
End Sub


Now: I seem to remember there is an issue with this collection: if you
iterate it forwards, it deletes only every second one because each time you
delete one, you delete number 2 and number 3 becomes number 2, then your
macro deletes 3 which was four and you miss 3 which is now 2. You with me??
{Big grin: it took me ages to find that problem: I know Footnotes does it,
and I think Hyperlinks does too...)

So you may need to change that to:

Sub DeleteHyperlinks()
For alink = ActiveDocument.Hyperlinks.count to 1 step -1
alink.Delete
Next alink
End Sub

That makes it run backwards and gets around the problem if each time you
delete a member the collection re-collates and you miss the next one :)

Hope this helps



from "Ric said:
Thanks for replying. You are confusing hypertext formatting with the
hypertext itself - two different things. What I am trying to do is to remove
the hyperlink from the text, but not the text itself. Making text a hyperlink
is
more than just applying a blue underlined format - it's embedding field (like
a cross reference field) into the text. If you right-click on the text that it
hypertexted, you can toggle the field to see the URL to which it links, but in
order to remove the link I need to open the link (select Hyperlink/Edit
Hyperlink) and click the "Remove Hyperlink" button. What I want is a way to
globally remove all the hyperlinks in the document rather than having to
delete them one at a time. Replace doesn't seem to work since it does not
appear that a hyperlink is a attribute like a format, nor a special character
like a paragraph mark, tab, etc. But something tells me there is a trick way
of doing this - I just don't know what it is and can't find it in the on-line
help.

--

Please respond only to the newsgroup to preserve the thread.

John McGhie, Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. GMT + 10 Hrs
+61 4 1209 1410, mailto:[email protected]
 
R

Ric Barline

Thanks Jamie. As I said in my post, the job can be done without resorting to
a macro (and without taking the time to figure out why they don't give the
expected results :~) by simply selecting all and doing Shift-Cmd-F9 which
apparently somehow disconnects all fields from the associated text.
According to Dayo, who provided this answer, this will zap all fields in the
document, so can't be used without taking some precautions, but in my case
there were no other fields, so it was the perfect choice. Anyway, I am
fascinated with macros, and will certainly try out yours, but I don't know VB
well enough to troubleshoot them. I need to learn VB! Anyway, thanks again
everyone who offered their assistance with my question. I think these
discussion groups are fantastic! I have yet to not get my problem solved by
coming here.
 
J

John McGhie [MVP - Word]

Hi Ric:

Dayo got one over me there :) The reason I did not suggest that is that
Shift + F9 removes ALL of the fields, including all your cross-referencing
and numbering and includes... In your document this is obviously OK, but in
mine that would do too much damage :)

Cheers


from "Ric said:
Thanks Jamie. As I said in my post, the job can be done without resorting to
a macro (and without taking the time to figure out why they don't give the
expected results :~) by simply selecting all and doing Shift-Cmd-F9 which
apparently somehow disconnects all fields from the associated text.
According to Dayo, who provided this answer, this will zap all fields in the
document, so can't be used without taking some precautions, but in my case
there were no other fields, so it was the perfect choice. Anyway, I am
fascinated with macros, and will certainly try out yours, but I don't know VB
well enough to troubleshoot them. I need to learn VB! Anyway, thanks again
everyone who offered their assistance with my question. I think these
discussion groups are fantastic! I have yet to not get my problem solved by
coming here.

--

Please respond only to the newsgroup to preserve the thread.

John McGhie, Consultant Technical Writer,
McGhie Information Engineering Pty Ltd
Sydney, Australia. GMT + 10 Hrs
+61 4 1209 1410, mailto:[email protected]
 
D

Dayo Mitchell

I think at some point he mentioned thousands of hyperlinks, and any doc with
thousands of hyperlinks AND cross-references AND numbering perhaps deserves
to be destroyed. :))) just kidding

But I warned him first, of course.

And Ric, Word's term is "unlink a field" and the Help topic (not all that
helpful in 2001) is something like "prevent changes to information inserted
by a field." They might provide a little more info.

Dayo
 

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