Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 11-13-2022, 04:51 AM
Italophile Italophile is offline Place Hyperlink text inline Windows 11 Place Hyperlink text inline Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

The following code will process the hyperlinks and the referenced bookmarked locations in the same document. The hyperlinks are replaced with the text from the bookmark and will retain the formatting of that text.

Code:
Sub MoveHyperlinkedText()
    Dim hlIdx As Long, hlink As Hyperlink, hlRng As Range
    Dim bmName As String, bmRng As Range
    
    If ActiveDocument.Hyperlinks.Count > 0 And ActiveDocument.Bookmarks.Count > 0 Then
        Application.ScreenUpdating = False
        'because hyperlinks will be deleted it is necessary to process them in reverse order
        For hlIdx = ActiveDocument.Hyperlinks.Count To 1 Step -1
            Set hlink = ActiveDocument.Hyperlinks(hlIdx)
            If hlink.Type = msoHyperlinkRange Then  'ignore any hyperlinked shapes
                If hlink.Address = vbNullString Then
                    'it's a link to a location in the same document so ensure that it exists
                    bmName = hlink.SubAddress
                    If ActiveDocument.Bookmarks.Exists(bmName) Then
                        'get range of bookmarked paragraph, minus the paragraph mark
                        Set bmRng = ActiveDocument.Bookmarks(bmName).Range
                        With bmRng
                            .Expand wdParagraph
                            .End = .End - 1
                        End With
                        Set hlRng = hlink.Range
                        hlink.Delete
                        With hlRng
                            'turn off superscript and replace text with brackets
                            .Font.Superscript = False
                            .Text = " []"
                            .Start = .Start + 2
                            .End = .End - 1
                            'add the bookmarked text and its formatting
                            .FormattedText = bmRng.FormattedText
                        End With
                    End If
                End If
            End If
        Next hlIdx
        Application.ScreenUpdating = True
    End If

End Sub
Reply With Quote
 

Tags
hyperlink text



Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlink to specific place in PDF michal.berenc Visio 1 11-23-2017 08:55 AM
Creating A Keyboard Shortcut In Place of Using Mouse To Select Hyperlink Object PowerPointerNeedsHelp PowerPoint 3 07-06-2017 01:47 AM
Place Hyperlink text inline How to put a table inline with the text Subterfuge Word Tables 2 09-22-2016 08:01 AM
Place Hyperlink text inline Hyperlink to Place in Document Issue atelem Word 9 06-22-2016 03:31 PM
Place Hyperlink text inline editing a number/text at one place and changes taking place wherever it appears anurag.butoliya Word 1 06-14-2014 06:27 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:42 PM.


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