1
votes

I am generating a bibliography with a series of hyperlinks, and I would like to parse a string from the end of the hyperlink to use as the TextToDisplay.

This is a sample hyperlink: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC#######

I would like TextToDisplay to equal PMC#######

This string of length 10 will always be PMC + 7 digits that uniquely identify each reference; it will always start at position 43.

I found code on this site to create a generic TextToDisplay link, but in this case I need to have a dynamic TextToDisplay for each unique link. Here was the code for the generic conversion:

Public Sub ChangeHyperlinksText()

    Dim hlink As Hyperlink

    For Each hlink In ActiveDocument.Hyperlinks
        hlink.TextToDisplay = "Link"
    Next hlink

End Sub

Is it possible to add specific TextToDisplay based on each hyperlink?

Thanks for your assistance.

1

1 Answers

0
votes

Yes, that is very simple to do.

Public Sub ChangeHyperlinksText()
  Dim hlink As Hyperlink
  For Each hlink In ActiveDocument.Hyperlinks
    hlink.TextToDisplay = Right(hlink.Address, 10)
  Next hlink
End Sub