none
How to edit hyperlinks in footnotes of word document using vba for word? RRS feed

  • Question

  • Hi,

    I am not able to edit hyperlink in footnote of word document.My vba code is working fine with other body but its not working in footer .Please help

    Sub removeDeepLink()

    Dim link As Hyperlink, strng As String, ulink As String, f As Integer

    For f = 1 To ActiveDocument.Hyperlinks.Count
        strng = ActiveDocument.Hyperlinks(f).Address
        ulink = Mid(strng, 1, InStr(1, strng, ".com") + 3)
        ActiveDocument.Hyperlinks(f).Address = ulink
    Next
    'MsgBox "Update done"
    End Sub

    Tuesday, September 29, 2015 7:43 AM

Answers

  • Try:

    Sub RemoveDeepLinks()
    Application.ScreenUpdating = False
    Dim Sctn As Section, HdFt As HeaderFooter
    With ActiveDocument
      Call UpdateHyperlinks(.Range)
      For Each Sctn In .Sections
        For Each HdFt In Sctn.Headers
          With HdFt
            If .LinkToPrevious = False Then
              Call UpdateHyperlinks(.Range)
            End If
          End With
        Next
        For Each HdFt In Sctn.Footers
          With HdFt
            If .LinkToPrevious = False Then
              Call UpdateHyperlinks(.Range)
            End If
          End With
        Next
      Next
    End With
    Application.ScreenUpdating = True
    MsgBox "Update done"
    End Sub

    Sub UpdateHyperlinks(Rng As Range)
    Dim Hlnk As Hyperlink
    For Each Hlnk In Rng.Hyperlinks
      With Hlnk
        .Address = Left(.Address, InStr(.Address, ".com") + 3)
      End With
    Next
    End Sub

    Note that I've included code to process headers as well. The code still doesn't process links in textboxes, footnotes, etc.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, September 30, 2015 1:38 AM

All replies

  • Try:

    Sub RemoveDeepLinks()
    Application.ScreenUpdating = False
    Dim Sctn As Section, HdFt As HeaderFooter
    With ActiveDocument
      Call UpdateHyperlinks(.Range)
      For Each Sctn In .Sections
        For Each HdFt In Sctn.Headers
          With HdFt
            If .LinkToPrevious = False Then
              Call UpdateHyperlinks(.Range)
            End If
          End With
        Next
        For Each HdFt In Sctn.Footers
          With HdFt
            If .LinkToPrevious = False Then
              Call UpdateHyperlinks(.Range)
            End If
          End With
        Next
      Next
    End With
    Application.ScreenUpdating = True
    MsgBox "Update done"
    End Sub

    Sub UpdateHyperlinks(Rng As Range)
    Dim Hlnk As Hyperlink
    For Each Hlnk In Rng.Hyperlinks
      With Hlnk
        .Address = Left(.Address, InStr(.Address, ".com") + 3)
      End With
    Next
    End Sub

    Note that I've included code to process headers as well. The code still doesn't process links in textboxes, footnotes, etc.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, September 30, 2015 1:38 AM
  • Hi sharjil,

    >> I am not able to edit hyperlink in footnote of word document.My vba code is working fine with other body but its not working in footer

    I am not sure where hyperlinks you want. Footnotes and footers are different. You could refer the suggestion from macropod for headers and footers. If you want to get the hyperlinks from footnotes. You could refer the code below:

    Dim a As Footnote
    'footnotes hyperlinks
    For Each a In ActiveDocument.Footnotes
      For Each b In a.Range.Hyperlinks
      Debug.Print b.Name
      Next
    Next

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, September 30, 2015 2:39 AM
  • Thank you very much .Your code really worked.
    Wednesday, September 30, 2015 12:22 PM
  • Thanks your code helped me a lot.
    Wednesday, September 30, 2015 12:22 PM
  • Hi sharjil,

    I am glad your issue has been resolved.

    I suggest you mark the helpful reply as answer to close this thread.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, October 1, 2015 9:19 AM