Hyper link removal

B

Bhagiratha

Hi

I have downloaded a few web pages that I am editing in word 2004. the
problem is that, the document contains alot of words have have
hyperlinks attach to them. I know that I could remove them one by one,
but this takes along time to do.

I would like to know if there is a way to remove All the hyperlinks in
the document all at once.

thank you.
 
D

Daiya Mitchell

A Hyperlink is a field.  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, cmd-shift-F9 will kill
those too. In that case, cmd-Y for redo might save a keystroke. Still
easier to do that one by one than Insert | Hyperlink, click Remove, click
OK.

Alternatively, I think there is an untested macro floating around that
deletes only hyperlinks, if you search the archives of the group.
http://groups.google.com/group/microsoft.public.mac.office.word
 
M

matt neuburg

Bhagiratha said:
Hi

I have downloaded a few web pages that I am editing in word 2004. the
problem is that, the document contains alot of words have have
hyperlinks attach to them. I know that I could remove them one by one,
but this takes along time to do.

I would like to know if there is a way to remove All the hyperlinks in
the document all at once.

tell application "Microsoft Word"
delete every hyperlink object of active document
end tell

m.
 
J

John McGhie [MVP - Word and Word Macintosh]

Matt:

Very nice... Have you tested that in a long doc?

The VBA equivalent has a bug: if you use a For... Each ... Next loop, you
get only every "second" hyperlink, because the collection re-numbers with
each deletion.

Have they fixed that in AppleScript?

In VBA you have to:

Sub Main()
' Removes hyperlinks from document
' Macro written 1 Aug 2001 by John McGhie

For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
ActiveDocument.Hyperlinks(i).Delete
Next i

End Sub

Cheers


tell application "Microsoft Word"
delete every hyperlink object of active document
end tell

m.

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
M

matt neuburg

John McGhie said:
Matt:

Very nice... Have you tested that in a long doc?

The VBA equivalent has a bug: if you use a For... Each ... Next loop, you
get only every "second" hyperlink, because the collection re-numbers with
each deletion.

Have they fixed that in AppleScript?

In VBA you have to:

Sub Main()
' Removes hyperlinks from document
' Macro written 1 Aug 2001 by John McGhie

For i = ActiveDocument.Hyperlinks.Count To 1 Step -1
ActiveDocument.Hyperlinks(i).Delete
Next i

End Sub

If that problem arises with the AS version, the equivalent fix would be:

tell application "Microsoft Word"
tell active document
repeat with i from (count hyperlink objects) to 1 by -1
delete hyperlink object i
end repeat
end tell
end tell

m.
 
J

JE McGimpsey

Matt:

Very nice... Have you tested that in a long doc?

The VBA equivalent has a bug: if you use a For... Each ... Next loop, you
get only every "second" hyperlink, because the collection re-numbers with
each deletion.

Have they fixed that in AppleScript?

It's worse in Applescript. Only the first hyperlink is deleted with
Matt's first suggestion ("delete every hyperlink object of active
document"). With his fix, they all were deleted, but it took 58 seconds
to delete 20 hyperlinks on my 1.3GHz PB.

As for Word/VBA, what a stupid bug, and how stupid not to fix it (the
For...Each...Next construction works fine in XL, so it's a Word Object
Model problem).

I use a slightly different method - don't see a real advantage other
than not needing a variable. Using With...End With should make it
significantly faster since there's no need to resolve the object each
time:

With ActiveDocument.Hyperlinks
Do While .Count > 0
.Item(1).Delete
Loop
End With

In comparison to the Applescript version, that routine took less than
three, still agonizingly slow, seconds.
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi John:

Oh, VERY eloquent :)

I have always shied away from testing .Count within a loop, because under
some circumstances that seems to cause the interpreter to re-enumerate the
collection on each evaluation. This can be astonishingly resource-hungry.

In this case, it appears that it doesn't, at least in Mac Word :)

Cheers


It's worse in Applescript. Only the first hyperlink is deleted with
Matt's first suggestion ("delete every hyperlink object of active
document"). With his fix, they all were deleted, but it took 58 seconds
to delete 20 hyperlinks on my 1.3GHz PB.

As for Word/VBA, what a stupid bug, and how stupid not to fix it (the
For...Each...Next construction works fine in XL, so it's a Word Object
Model problem).

I use a slightly different method - don't see a real advantage other
than not needing a variable. Using With...End With should make it
significantly faster since there's no need to resolve the object each
time:

With ActiveDocument.Hyperlinks
Do While .Count > 0
.Item(1).Delete
Loop
End With

In comparison to the Applescript version, that routine took less than
three, still agonizingly slow, seconds.

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
M

Matt Centurión [MSFT]

Hi JE, I'm confused as to why you say Matt's original suggestion doesn't
work:

delete every hyperlink object of active document

works fine in my documents and takes no time at all to remove all
hyperlinks. Let me know if it's a particular set of hyperlinks or any other
information that could help identify the problem.

Matt
MacWord Testing
Microsoft
 
J

JE McGimpsey

Posted and emailed. Please reply in the newsgroup.

Matt Centurion said:
Hi JE, I'm confused as to why you say Matt's original suggestion doesn't
work:

delete every hyperlink object of active document

Well, only because with my test doc:

ftp://ftp.mcgimpsey.com/word/quick.doc

and this script

tell application "Microsoft Word"
delete every hyperlink object of active document
end tell

only the first of 5 hyperlinks are deleted when I click Run, in Script
Editor (2.1.1(81), AppleScript 1.10.3).

Using Word 11.2 (050714) on Mac OS X 10.4.3 (8F46)
works fine in my documents and takes no time at all to remove all
hyperlinks. Let me know if it's a particular set of hyperlinks or any other
information that could help identify the problem.

Let me know how it works for you...
 
M

Matt Centurión [MSFT]

Date: 11/28/05 11:56 AM / From: "JE McGimpsey said:
Well, only because with my test doc:
and this script

tell application "Microsoft Word"
delete every hyperlink object of active document
end tell

only the first of 5 hyperlinks are deleted when I click Run, in Script
Editor (2.1.1(81), AppleScript 1.10.3).

Using Word 11.2 (050714) on Mac OS X 10.4.3 (8F46)

Hrm, I see your issue now. For some reason this worked for me but it must
have been the time of the day, alignment of the moon, and the fact that I
have access to the next version of Word which I may have been using by
mistake. ( Next version spoiler :p )

Matt
MacWord Testing
Microsoft
 

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