![]() |
|
|
|
#1
|
|||
|
|||
|
Hi all,
Is it possible to convert all "url-text" to hyperlinked text? I googled several methods, but all methods seems only applied to main text but not footnote section. For example: https://www.datanumen.com/blogs/5-wa...word-document/ This site provides "auto format" method, but auto format seems not applies to footnote or endnote section. Anyone can help? Thanks in advance!! |
|
#2
|
||||
|
||||
|
Try:
Code:
Sub ConvertURLTextsToHyperlinksInDoc()
Application.ScreenUpdating = False
Dim wdRng As Range
For Each wdRng In ActiveDocument.StoryRanges
With wdRng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "htt[ps]{1,2}://[!^13^t^l ^s]{1,}"
.Replacement.Text = ""
.Forward = True
.Format = False
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
If .Characters.Last Like "[:;.,(?)!})]" Then .End = .End - 1
.Hyperlinks.Add .Duplicate, .Text, , , .Text
.Start = .Hyperlinks(1).Range.End
.Find.Execute
Loop
End With
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Thank you very much for you reply!!
But in my word file the "url-text" usually ends with a period or a semicolon and it will make a dead hyperlink (the correct url should not include the period/semicolon). Could you kindly teach me how to trim the last character if the url-text ends with a period/semicolon? ![]()
|
|
#4
|
|||
|
|||
|
Thank you very much!!
It really saved me a lot of time! I revised the code a little bit as below: Quote:
|
|
#5
|
||||
|
||||
|
Your 'revision' makes the trimming less comprehensive than my code. I doubt you really want to include punctuations other than '.' & ':', or closing parentheses & braces, as part of the hyperlink.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#6
|
|||
|
|||
|
I tried to use your code , but it seemed unable to trim the unwanted punctuations.
For example, Code:
Roa, Felipe Suescun de, Comments on the ICSID Award Saipem v. Bangladesh: Would its rationale be applicable in future cases?, INT'L INST. FOR CONFLICT PREVENTION & RESOL. (May 5, 2011), http://www.cpradr.org/news-publications/articles/2011-05-05-comments-on-the-icsid-award-saipem-v-bangladesh-would-its-rationale-be-applicable-in-future-cases-2011-writing-contest-winner. Code:
Sub ConvertURLTextsToHyperlinksInDoc()
Dim wdRng As Range
For Each wdRng In ActiveDocument.StoryRanges
With wdRng
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "htt[ps]{1,2}://[!^13^t^l ]{1,}"
.Replacement.Text = ""
.Forward = True
.Format = False
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
If .Characters.Last Like "[!:;.,?})]" Then .End = .End - 1
.Hyperlinks.Add .Duplicate, .Text, , , .Text
.Start = .Hyperlinks(1).Range.End
.Find.Execute
Loop
End With
Next
End Sub
|
|
#7
|
||||
|
||||
|
Try using:
If Not .Characters.Last.Text Like "[0-9A-Za-z]" Then .End = .End - 1 or, if you data include high-end ASCII characters: If Not .Characters.Last.Text Like "[0-9A-Za-zĄ-’]" Then .End = .End - 1
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#8
|
|||
|
|||
|
Is there a way to include text starting with "www" in this code? I tried:
.Text = "htt[ps]{1,2}://[!^13^t^l ]{1,}" Or .Text = "www{1,2}://[!^13^t^l ]{1,}" but it produces an error in runtime. My workaround would be to just run the code a second time but for "www" instead of "htt[ps]", but I'd rather just run it once and cover all three "http", "https", and "www" instances. |
|
#9
|
||||
|
||||
|
You cannot use OR functions in the Find expression. You might, however, use:
.Text = "[wh][wt][wtps]{1,3}[./][!^13^t^l ^s]{1,}"
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#10
|
|||
|
|||
|
Wow - I never would have figured that out! Thanks, Macropod.
|
|
| Tags |
| footnote, hyperlink |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Convert endnote/footnote to regular text
|
Cobb78 | Word | 5 | 07-11-2016 06:23 AM |
Footnote numbering problem within single section
|
jsswadley | Word | 2 | 03-17-2015 04:44 PM |
Convert Word Document including FOOTNOTE into Outlook Message
|
withers | Word | 1 | 08-21-2014 05:03 AM |
How to have "Footnote" in section different from the section for the words it refers
|
Jamal NUMAN | Word | 2 | 07-03-2011 03:06 AM |
| Microsoft word hyperlink to section in a pdf | Ian55555 | Word | 0 | 09-29-2009 09:30 PM |