![]() |
|
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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 |
|
#5
|
|||
|
|||
|
Yes, that's it!
Thank you very much. |
|
| 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 |
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 |