Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-04-2023, 08:35 AM
WJSwanepoel WJSwanepoel is offline Hyperlink text to Footnote Windows 10 Hyperlink text to Footnote Office 2021
Advanced Beginner
Hyperlink text to Footnote
 
Join Date: Dec 2019
Location: Krugersdorp, South Africa
Posts: 65
WJSwanepoel is on a distinguished road
Question Hyperlink text to Footnote

I am trying to use a macro to turn text at hyperlinks into footnotes. My Macro looks like this:
Code:
Sub HLnk2FtNt()
Application.ScreenUpdating = False
Dim h As Long, Rng As Range
With ActiveDocument
  For h = .Hyperlinks.Count To 1 Step -1
    With .Hyperlinks(h)
      Set Rng = .Range
      With Rng
        .Collapse wdCollapseEnd
        .Footnotes.Add Rng
        .End = .End + 1
      End With
      Rng.Footnotes(1).Range.FormattedText = .Range.FormattedText
      .Range.Fields.Unlink
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
It however does not do what I want.
I attach the original Word document: SmallTest.docx
The file after running the macro: SmallTest_AfterMacro.docx and
A document showing what I actually want.

Any help will be much appreciated.
Attached Files
File Type: docx SmallTest.docx (12.3 KB, 3 views)
File Type: docx SmallTest_AfterMacro.docx (14.3 KB, 1 views)
File Type: docx SmallTest_Correct.docx (15.5 KB, 1 views)
Reply With Quote
  #2  
Old 04-05-2023, 12:15 AM
WJSwanepoel WJSwanepoel is offline Hyperlink text to Footnote Windows 10 Hyperlink text to Footnote Office 2021
Advanced Beginner
Hyperlink text to Footnote
 
Join Date: Dec 2019
Location: Krugersdorp, South Africa
Posts: 65
WJSwanepoel is on a distinguished road
Default Partial Solution

I have it partially solved using this code:
Code:
Sub HLnk2FtNt()
Application.ScreenUpdating = False
Dim h As Long, Rng As Range
With ActiveDocument
  For h = .Hyperlinks.Count To 1 Step -1
    With .Hyperlinks(h)
         Set Rng = .Range
         With Rng
              .Collapse wdCollapseEnd
              .Footnotes.Add Rng
              .End = .End + 1
         End With
         bmName = .SubAddress
         Set hlRng = ActiveDocument.Bookmarks(bmName).Range
         ActiveDocument.Hyperlinks(h).Delete
         With hlRng
              .Expand wdParagraph
              .Start = .Start + 2
              .End = .End - 1
         End With
         Rng.Footnotes(1).Range.FormattedText = hlRng.FormattedText
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
There is one problem left. The piece of text that was the original Hyperlink still sits there. See attached file: PartialSolution.docx.

How can I remove that as well?
Attached Files
File Type: docx PartialSolution.docx (14.7 KB, 2 views)

Last edited by WJSwanepoel; 04-05-2023 at 12:16 AM. Reason: Fix Typo
Reply With Quote
Reply

Tags
footnotes, hyperlinks



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlink text to Footnote Macro to change font size of Footnote Reference in Footnote Text TheBigBoss Word VBA 5 06-10-2022 06:14 AM
Hyperlink text to Footnote Convert plaintext to hyperlink in footnote section henrychang Word VBA 9 04-15-2022 05:42 PM
Hyperlink text to Footnote Removing line break and indentation between footnote number and footnote text in Word jaanross Word 5 02-06-2020 12:04 AM
Hyperlink text to Footnote Adding footnote number as part of footnote text NoCalScribe Word VBA 3 07-15-2019 07:20 PM
Hyperlink text to Footnote Space between footnote number and footnote text Sabya Word 6 07-29-2018 02:30 PM

Other Forums: Access Forums

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