Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-19-2020, 10:36 AM
pjs15 pjs15 is offline Convert hyperlinked text to text followed by URL Windows 10 Convert hyperlinked text to text followed by URL Office 2019
Novice
Convert hyperlinked text to text followed by URL
 
Join Date: Feb 2020
Posts: 7
pjs15 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 07-19-2020, 04:15 PM
Guessed's Avatar
Guessed Guessed is offline Convert hyperlinked text to text followed by URL Windows 10 Convert hyperlinked text to text followed by URL Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 07-20-2020, 04:38 AM
pjs15 pjs15 is offline Convert hyperlinked text to text followed by URL Windows 10 Convert hyperlinked text to text followed by URL Office 2019
Novice
Convert hyperlinked text to text followed by URL
 
Join Date: Feb 2020
Posts: 7
pjs15 is on a distinguished road
Default

Awesome. This will save me tons of time. Much appreciated!
Reply With Quote
Reply

Tags
hyperlinks, urls

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert hyperlinked text to text followed by URL 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 hyperlinked text to text followed by URL 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft