Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-26-2025, 10:53 PM
geotso geotso is offline add some text before hyperlink fields Windows 11 add some text before hyperlink fields Office 2021
Novice
add some text before hyperlink fields
 
Join Date: Feb 2021
Posts: 3
geotso is on a distinguished road
Default add some text before hyperlink fields

Hello,


I have some URLs, each one at the start of a new paragraph like "http://something" or "https://something" (without quotes) and I want to add before them a label "URL: ", like "URL: http://something" or "URL: https://something" (without quotes).


I've tried find and replace for: find ^phttp, replace with ^pURL: http, however it doesn't work, because the URLs are hyperlink fields and Word can't match the string.


Then, I tried to use: Alt+F9 to get the field codes and then find "^p{HYPERLINK http", that doesn't work either, because the "{" of the filed is not the same with the one of the keyboard...


Any thoughts?
Thanks
Reply With Quote
  #2  
Old 09-27-2025, 12:28 AM
gmayor's Avatar
gmayor gmayor is offline add some text before hyperlink fields Windows 10 add some text before hyperlink fields Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Easy enough with a simple macro e.g
Code:
Sub Macro1()
Dim oLink As Hyperlink
Dim oRng As Range
    For Each oLink In ActiveDocument.Hyperlinks
        If oLink.Address Like "http*" Or oLink.Address Like "HTTP*" Then
            Set oRng = oLink.Range
            oRng.InsertBefore "URL: "
        End If
    Next oLink
End Sub
See Installing Macros
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 09-29-2025, 11:43 PM
geotso geotso is offline add some text before hyperlink fields Windows 11 add some text before hyperlink fields Office 2021
Novice
add some text before hyperlink fields
 
Join Date: Feb 2021
Posts: 3
geotso is on a distinguished road
Default

well, it's almost there...
I have to specify that I want the label only to the links at the start of a new line (paragraph or custom brake), and not the others, scattered all around the document.


Thanks
Reply With Quote
  #4  
Old 09-30-2025, 12:20 AM
gmayor's Avatar
gmayor gmayor is offline add some text before hyperlink fields Windows 10 add some text before hyperlink fields Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Oops. I missed that bit
Try this one
Code:
Sub Macro1()
Dim oLink As Hyperlink
Dim oRng As Range
    For Each oLink In ActiveDocument.Hyperlinks
        If oLink.Address Like "http*" Or oLink.Address Like "HTTP*" Then
            Set oRng = oLink.Range
            If oRng.Start = oRng.Paragraphs(1).Range.Start Then
                oRng.InsertBefore "URL: "
            End If
        End If
    Next oLink
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 09-30-2025, 11:53 PM
geotso geotso is offline add some text before hyperlink fields Windows 11 add some text before hyperlink fields Office 2021
Novice
add some text before hyperlink fields
 
Join Date: Feb 2021
Posts: 3
geotso is on a distinguished road
Default

Yes, that's it!


Thank you very much.
Reply With Quote
Reply

Tags
field, find & replace, hyperlink



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word macro to cut a range of text and apply to subsequent text as a hyperlink scientist101 Word VBA 9 07-20-2020 04:57 PM
Entering text next to hyperlink copies the hyperlink style abeneschan Word 0 07-23-2018 02:36 PM
VBA Search Table for Text/Select Text/Insert Hyperlink sldrellich Word VBA 3 03-24-2015 01:09 PM
add some text before hyperlink fields Hyperlink Fields to steps? autumnfire Word 5 10-31-2011 07:13 AM
Hyperlink address fields from Excel BongoBill Word 0 04-13-2010 04:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:01 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