Consulting

Results 1 to 2 of 2

Thread: Toggle Shortened hyper to full url (include footnotes)

  1. #1

    Toggle Shortened hyper to full url (include footnotes)

    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!

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •