Convert hyperlink to plain text anchor tag

W

wagster

I have a book with around 2000-3000 hyperlinks in it as a work document that
I have to reformat as am XML document for Flash to read. I need to convert
the hyperlink field codes to a standard html anchor tag - i.e.:

{ HYPERLINK "http://en.wikipedia.org/" \o "Wikipedia" }

becomes

<a href = "http://en.wikipedia.org/">Wikipedia</a>

I've tried doing ALT+F9 to display field codes, then copying and pasting
into notepad (I can search and replace to convert the tags easily enough) but
it won't copy the contents of the fields. I've tried saving as html, but
that way you end up with more formatting than anything else.

Does anyone know of a solution to this?
 
J

Jay Freedman

I have a book with around 2000-3000 hyperlinks in it as a work document that
I have to reformat as am XML document for Flash to read. I need to convert
the hyperlink field codes to a standard html anchor tag - i.e.:

{ HYPERLINK "http://en.wikipedia.org/" \o "Wikipedia" }

becomes

<a href = "http://en.wikipedia.org/">Wikipedia</a>

I've tried doing ALT+F9 to display field codes, then copying and pasting
into notepad (I can search and replace to convert the tags easily enough) but
it won't copy the contents of the fields. I've tried saving as html, but
that way you end up with more formatting than anything else.

Does anyone know of a solution to this?

Use this macro (see http://www.gmayor.com/installing_macro.htm if needed):

Sub ChangeHyperlinksToAnchors()
Dim idx As Long
Dim HL As Hyperlink
Const qot = """"

For idx = ActiveDocument.Hyperlinks.Count To 1 Step -1
Set HL = ActiveDocument.Hyperlinks(idx)
HL.Range.Text = _
"<a href = " & qot & _
HL.Address & qot & _
">" & HL.TextToDisplay & _
"</a>"
Next
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