#1
|
|||
|
|||
Convert hyperlinked text to text followed by URL
I often need to paste Word documents with hyperlinks into a plain text editor/platform, which strips out hyperlinks. So I don't have to then manually insert the links, is there a Word macro that can convert each hyperlink into its corresponding html? Here's what I want to do for all hyperlinks in a document:
Transform hyperlinked text such as "as reported in NEJM" which, when clicked, goes to https://www.nejm.org/doi/full/10.1056/nejmoa1112010 and replace it with: <a target="_blank" href="https://www.nejm.org/doi/full/10.1056/nejmoa1112010">as reported in NEJM</a>Thanks in advance for any suggestions. pjs |
#2
|
||||
|
||||
Try this
Code:
Sub Hyp2HTML() Dim aHL As Hyperlink, sPref As String, aRng As Range sPref = "<a target='_blank' href='" For Each aHL In ActiveDocument.Hyperlinks Set aRng = aHL.Range aRng.InsertBefore sPref & aHL.Address & "'>" aRng.InsertAfter "</a>" Next aHL End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Awesome. This will save me tons of time. Much appreciated!
|
Tags |
hyperlinks, urls |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
I need to convert shaded text into highlighted text on about 80 different long documents. VBA macro? | AustinBrister | Word VBA | 8 | 05-28-2015 02:42 PM |
Convert image-text hybrids into plain text | morlack | Excel | 4 | 12-03-2014 05:29 PM |
My plain text post got converted to rich text in a reply, how to convert it back? | david.karr | Outlook | 0 | 01-05-2012 09:46 AM |
Searhc for Hyperlinked Word and replace with plain text or nothing | somniloquist | Word | 3 | 10-04-2011 02:33 AM |
Why isn't my hyperlinked word text hyperlinked when I convert it to pdf? | Obisco | Word | 0 | 12-10-2010 01:58 PM |