Help Needed: Convert Word Marco to Change Link Display Name in Word

Thank you for reading this …

There is a macro in MS Word (Windows) that converts the display name of a link to a word, “Link” and retains the underlying URL info.

How can I convert this to Applescript/Automator and apply it in Word?

See this script.

Sub AllURLsSayLink()
Dim HL As Hyperlink
For Each HL In ActiveDocument.Hyperlinks
HL.TextToDisplay = “Link”
Next
End Sub

This will change only the displayed text, not the address or the tooltip (which will show the address).

I have also been referred to this script…

Sub changeHyperlinks()
Dim hl As Hyperlink
For Each hl In ActiveDocument.Hyperlinks
hl.TextToDisplay = “Link”
Next hl
End Sub

=============================

Is there any way to auto format multiple links in a Word documents to simply say “Link”, while of course retaining the underlying and correct URL address?

I have thousands of bibliographic citations that currently read like this…

Higashi, Y., Chayama, K., and Yoshizumi, M.(2005) Angiotensin II type I receptor blocker and endothelial function in humans: role of nitric oxide and oxidative stress. Curr.Med.Chem.Cardiovasc.Hematol.Agents: (3) 133-148.
http://www.ncbi.nlm.nih.gov/pubmed/15853700

Gerritsen, M. E.(2005) Genetic variations in vascular endothelial growth factor and endothelial nitric oxide synthase and their contributions to human disease. Microcirculation.: (12) 129-140.
http://www.ncbi.nlm.nih.gov/pubmed/15825252

But for a Web Page project need to read like this.

Higashi, Y., Chayama, K., and Yoshizumi, M.(2005) Angiotensin II type I receptor blocker and endothelial function in humans: role of nitric oxide and oxidative stress. Curr.Med.Chem.Cardiovasc.Hematol.Agents: (3) 133-148.
Link

Gerritsen, M. E.(2005) Genetic variations in vascular endothelial growth factor and endothelial nitric oxide synthase and their contributions to human disease. Microcirculation.: (12) 129-140.
Link

.while retaining the underlying and correct URL address, which is different for each citation

Again I know that I can go “Edit Hyperlink” and change the display name to “Link”, but doing thousands of time seems daunting. I’ve tried search/replace “wildcard”, but have not been successful.

Thank you,

Hi theadler,

I just looked into the MS Word 2004 AppleScript Reference and found that Word features a «hyperlink object» (p. 128). The nice thing about a hyperlink object is that is also contains a «text to display» property, which returns or sets the specified hyperlink’s visible text in a document. So you might be able to iterate over all hyperlink objects in a document and modify their appearance.

Unfortunately I do not have MS Word installed on my private Mac, so I cannot provide you with sample code at this time.

But maybe someone else can help us both out.

This simple code works on my wife’s iBook (MS Word 2004):


tell application "Microsoft Word"
	tell document 1
		set allhyperlinks to every hyperlink object
		repeat with thehyperlink in allhyperlinks
			set text to display of thehyperlink to "Link"
		end repeat
	end tell
end tell

Please don’t post your inquiry on multiple forums. Thanks :wink:

Martin
Thank you. I am a script newb.
Can you please point me in the direction of what to do next with the script.
Thank you so much.

I tried Running selected text as a script
Script Editor inserts items into the Services menu that allows applications to run selected text as a script. In any application that supports the Services menu, you can select text and have AppleScript run it as a script.

Hi theadler,

Just paste and copy the AppleScript code above into a new Script Editor window (or simply click on «Open this Scriplet in your Editor»).

Then open a copy* of your document in Microsoft Word.

Switch back to the Script Editor and click the Run button of the window. Now the AppleScript will process the frontmost document in MS Word.

If this is successful, then you can save the script into an «Application bundle», so that you can execute it from your Dock, Script Menu, you name it :smiley:

If you need any additional advice, please do not hesitate to ask us.

  • It is good practice to test run posted code on a copy first.