How to check for hyperlinks in a macro

G

Gary Appenzeller

I create a table of hyperlinks. Some columns have every cell filled with
hyperlinks, some columns have some cells with a hyperlink or text or nothing.
I have written a macro that changes the hyperlinks to text. I would like to
kick it off and have it change what needs to be changed, but if it is text or
blank I would like to have the processing continue. Currently, it errors
when it encounters something other than a hyperlink. How do I check if what
is in a cell is a hyperlink? I want to modify the macro so that it does not
error.
 
B

Benjamino5

Gary,

Hyperlinks in Word have the style "Hyperlink," which you can search for.

Instead of looping through the cells of the table (if that's what you're
doing), could you instead do a find and replace across the table? Find all
text styled "Hyperlink" and turn it into regular text. That way, it will
simply ignore the plain text or the empty cells and keep going.

Hope this helps,
Ben
 
T

Tony Jollans

Strictly speaking it is possible to have hyperlinks with a non-hyperlink
style and non-hyperlink text with a hyperlink style so this method has some
drawbacks.

A better way to do it is to walk the hyperlinks collection ...

For each hyp in (table).range.hyperlinks
' do whatever
Next
 
D

Dafinga

Here is a quick macro I wrote that you can configure to your liking.
This macro finds all the hyperlinks and displays a count of how many in
your document. Than makes those hyperlinks into text with another
message box telling you it was complete.


CODE:
---------------------------------------------------------
Sub RemoveHyperLinks()
Dim hyperlnks As Long

' Numerical count of hyperlinks in document

With ActiveDocument
hyperlnks = .Hyperlinks.Count

' Verify how many hyperlinks are left in the document and Deletes them

msg = "There are "
msg = msg & hyperlnks & " Hyperlinks in this Document."
MsgBox msg
Do Until .Hyperlinks.Count = 0
.Hyperlinks(1).Delete
Loop

End With

' Numerical count of hyperlinks in document

With ActiveDocument
hyperlnks = .Hyperlinks.Count

' Verify how many hyperlinks are left in the document

msg = "There are "
msg = msg & hyperlnks & " Hyperlinks Left."
MsgBox msg

End With

End Sub
 

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