PDA

View Full Version : [SOLVED:] Toggle Shortened hyper to full url (include footnotes)



elev8
03-05-2021, 02:16 AM
So I have a macro here which toggles between Original hyperlink name> Renamed, shortened hyperlink. In this case "url"
Its working well, But I'm struggling to include footnotes in this code, tried a couple of different things but can't seem to get it working.

Sub ToggleURLs()
Dim aHL As Hyperlink
For Each aHL In ActiveDocument.Hyperlinks
If aHL.TextToDisplay = "url" Then
aHL.TextToDisplay = aHL.Address
Else
aHL.TextToDisplay = "url"
End If
Next aHL
End Sub


It seems this should be a simple addition somewhere, if someone can help will be much appreciated!

macropod
03-05-2021, 08:53 PM
For example:


Sub ToggleURLs()Dim RngStry As Range, HLnk As Hyperlink
For Each RngStry In ActiveDocument.StoryRanges
Select Case RngStry.StoryType
Case wdEndnotesStory, wdFootnotesStory, wdMainTextStory
For Each HLnk In RngStry.Hyperlinks
With HLnk
If .TextToDisplay = "url" Then
.TextToDisplay = .Address
Else
.TextToDisplay = "url"
End If
End With
Next
End Select
Next
End Sub
PS: You don't actually need any code to toggle between the hyperlink display and the URL - all you need do is press Alt-F9.