3

I like adding hyperlinks to my Word documents and e-mails in Outlook. I usually prefer to change the link Text to display to something more readable than just the URL. I follow patterns for some URLs. For example, we have a Confluence wiki, and I usually reformat the link text from

https://host/confluence/display/space/Some+Wiki+Page

to

Our Wiki - Some Wiki Page

Granted, the URL itself is fairly descriptive, but I still prefer a text form. I also like to format other links in this manner (for example, Amazon.com - Some Product).

Is there a way to create automatic rules for doing this formatting when pasting a link? Perhaps in a macro?

I will also accept an answer if there is a way to automatically bring up the Insert Hyperlink dialog when I paste a link.

1 Answer 1

0

This macro will paste a link you have in clipboard, to TextToDisplay="ref". Which you may edit in the macro to whatever you want, and make multiple macros with different TextToDisplay.

Someone could probably easily make this recognize a domain and preformat the text. But I had no need, so haven't done that.

To run this macro you must include a reference:

Tools > References > Browse > ..Windows\System32\FM20.dll , Open, OK (Adds MS Forms 2.0 Object Library)

This was done in Word 2003, so no promise for other versions, but will probably work.

For example, I made one called hyperlink_yt, which I use for youtube links with TextToDisplay="yt", assigned shortcut Alt+Y to this macro.

Sub hyperlink_ref()
' Makes clipboard-hyperlink ref
Dim MyData As DataObject
Dim strClip As String
Set MyData = New DataObject
MyData.GetFromClipboard
strClip = MyData.GetText
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=strClip, SubAddress:="", ScreenTip:="", TextToDisplay:="ref"
End Sub

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .