Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 07-16-2020, 06:31 PM
Guessed's Avatar
Guessed Guessed is offline Word macro to cut a range of text and apply to subsequent text as a hyperlink Windows 10 Word macro to cut a range of text and apply to subsequent text as a hyperlink Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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
Code:
Sub MakeMyLink()
  Dim aRng As Range, sFound() As String, sLink As String, sText As String
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .Text = "\<\<(*)\>\>\<\<(*)\>\>"
    .MatchWildcards = True
    .Replacement.Text = "\1|\2"
    Do While .Execute
      sFound = Split(aRng.Text, ">><<")
      sLink = Replace(sFound(0), "<<", "")
      sText = Replace(sFound(1), ">>", "")
      ActiveDocument.Hyperlinks.Add Anchor:=aRng, Address:=sLink, TextToDisplay:=sText
      aRng.Collapse Direction:=wdCollapseEnd
    Loop
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
 

Tags
hyperlinking, macro find text



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro how to add hyperlink to text in document hullsquashboy Word VBA 32 06-28-2022 06:30 PM
Highlighting applied to range ending in a paragraph continues to apply to text added after Peterson Word VBA 2 10-08-2018 02:50 PM
Word macro to cut a range of text and apply to subsequent text as a hyperlink Word changing my body text to heading text when I apply paragraph numbering ddiemetric Word 1 01-17-2017 01:10 PM
Microsoft Word macro to find text, select all text between brackets, and delete helal1990 Word VBA 4 02-05-2015 03:52 PM
Word macro to cut a range of text and apply to subsequent text as a hyperlink Formatting- Apply changes to highlighted text results in same change to other text sential Word 6 01-10-2014 03:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:41 AM.


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