Doug
Doug

Reputation: 1

In MS Word use macro to replace hyperlink text containing "#" and "!"

In a Microsoft Word document, using a macro I want to change links like https://www.library/#!/xyz to https://www.library2/xyz (where xyz indicates the specific resource and all other parts of these strings are constant).

The problem is that the "#!" characters in the original URL seem to terminate the string found by link.Address (and the "#!" is part of the original copied link -- not something I have a choice about).

My code:

Sub statelinks() 
    For Each link In ActiveDocument.Hyperlinks 
        MsgBox link.Address 
    Next
End Sub

For a document with one hyperlink https://www-clinicalkey-com.proxy.library.emory.edu/#!/content/book/3-s2.0-B9780323393041000038?scrollTo=%23hl0001812 the MsgBox shows https://www-clinicalkey-com.proxy.library.emory.edu/ (truncated immediately before the "#!").

How can I get the full URL?

Upvotes: 0

Views: 575

Answers (1)

Ike
Ike

Reputation: 13024

Either you can use link.TextToDisplay - if it is identical to the address itself.

Or you can "hack" it a little bit joining address and subaddress - as Word vba assumes the # to be the divider for the subaddress

link.Address & "#" & link.SubAddress

This doesn't work if there are two #s in the URL ...

Upvotes: 0

Related Questions