Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2018, 09:00 PM
henrychang henrychang is offline Convert plaintext to hyperlink in footnote section Windows 10 Convert plaintext to hyperlink in footnote section Office 2016
Novice
Convert plaintext to hyperlink in footnote section
 
Join Date: Jul 2018
Posts: 5
henrychang is on a distinguished road
Default Convert plaintext to hyperlink in footnote section


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!!
Reply With Quote
  #2  
Old 07-28-2018, 11:33 PM
macropod's Avatar
macropod macropod is offline Convert plaintext to hyperlink in footnote section Windows 7 64bit Convert plaintext to hyperlink in footnote section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 07-29-2018, 01:00 AM
henrychang henrychang is offline Convert plaintext to hyperlink in footnote section Windows 10 Convert plaintext to hyperlink in footnote section Office 2016
Novice
Convert plaintext to hyperlink in footnote section
 
Join Date: Jul 2018
Posts: 5
henrychang is on a distinguished road
Default

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?
Reply With Quote
  #4  
Old 07-30-2018, 05:51 AM
henrychang henrychang is offline Convert plaintext to hyperlink in footnote section Windows 10 Convert plaintext to hyperlink in footnote section Office 2016
Novice
Convert plaintext to hyperlink in footnote section
 
Join Date: Jul 2018
Posts: 5
henrychang is on a distinguished road
Default

Thank you very much!!
It really saved me a lot of time!
I revised the code a little bit as below:

Quote:
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 "." Or .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
Reply With Quote
  #5  
Old 07-30-2018, 02:51 PM
macropod's Avatar
macropod macropod is offline Convert plaintext to hyperlink in footnote section Windows 7 64bit Convert plaintext to hyperlink in footnote section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #6  
Old 07-31-2018, 12:41 AM
henrychang henrychang is offline Convert plaintext to hyperlink in footnote section Windows 10 Convert plaintext to hyperlink in footnote section Office 2016
Novice
Convert plaintext to hyperlink in footnote section
 
Join Date: Jul 2018
Posts: 5
henrychang is on a distinguished road
Default

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.
This url-text cannot be recognized correctly, still includes the last period.

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
Reply With Quote
  #7  
Old 07-31-2018, 01:39 AM
macropod's Avatar
macropod macropod is offline Convert plaintext to hyperlink in footnote section Windows 7 64bit Convert plaintext to hyperlink in footnote section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #8  
Old 04-15-2022, 08:38 AM
Marrick13 Marrick13 is offline Convert plaintext to hyperlink in footnote section Windows XP Convert plaintext to hyperlink in footnote section Office 2010 32bit
Competent Performer
 
Join Date: Jun 2006
Posts: 102
Marrick13 will become famous soon enough
Default ConvertURLTextsToHyperlinksInDoc

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.
Reply With Quote
  #9  
Old 04-15-2022, 04:22 PM
macropod's Avatar
macropod macropod is offline Convert plaintext to hyperlink in footnote section Windows 10 Convert plaintext to hyperlink in footnote section Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #10  
Old 04-15-2022, 05:42 PM
Marrick13 Marrick13 is offline Convert plaintext to hyperlink in footnote section Windows XP Convert plaintext to hyperlink in footnote section Office 2010 32bit
Competent Performer
 
Join Date: Jun 2006
Posts: 102
Marrick13 will become famous soon enough
Default

Wow - I never would have figured that out! Thanks, Macropod.
Reply With Quote
Reply

Tags
footnote, hyperlink



Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert plaintext to hyperlink in footnote section Convert endnote/footnote to regular text Cobb78 Word 5 07-11-2016 06:23 AM
Convert plaintext to hyperlink in footnote section Footnote numbering problem within single section jsswadley Word 2 03-17-2015 04:44 PM
Convert plaintext to hyperlink in footnote section Convert Word Document including FOOTNOTE into Outlook Message withers Word 1 08-21-2014 05:03 AM
Convert plaintext to hyperlink in footnote section 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

Other Forums: Access Forums

All times are GMT -7. The time now is 11:18 AM.


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