Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 07-20-2020, 03:59 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

This code is not super reusable because of the hard coding of the path to be removed. It is probably possible to make this adapt dynamically by looking at the folder path where the Word document is saved and finding the overlap with the file path to the hyperlinks but that will take a fair bit of extra coding.

This is how you could make it back into a single macro with a hard coded path
Code:
Sub MakeMyLink()
  Dim aRng As Range, sFound() As String, sLink As String, sText As String
  
  'configure path to remove the path overlaps and make hyperlinks 'relative' to the location of the Word doc
  Const sCommon As String = "C:\Users\iaman\Desktop\eCTD_Office_Software\IND_Source_Folders\YFV_IND"
  
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .Text = "\<\<(*)\>\>\<\<(*)\>\>"
    .MatchWildcards = True
    .Replacement.Text = "\1|\2"
    Do While .Execute
      sFound = Split(aRng.Text, ">><<")
      sText = Replace(sFound(1), ">>", "")
      sLink = Replace(sFound(0), "<<", "")
      sLink = Replace(sLink, sCommon, "..")
      sLink = Replace(sLink, "", "/")
      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 05:12 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