Document Editing Problems

Convert Word Hyperlink Text to URLs with VBA

Amos GikundaAmos Gikunda Nov 22, 2026 870 views

Question details

Replace hyperlink display text with the actual addresses before saving a Word document as plain text.

Convert Word Hyperlink Text to URLs with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
A document contains many hyperlinks whose formatted display text needs to be converted to visible URLs for a text file.
Observed behavior
The hyperlinks show descriptive text rather than the web addresses needed in the text file.
Before you start

Open the document in Word and check that the hyperlinks have external addresses. Enable the Developer tab in Word’s ribbon settings if it is not visible, and use macros only from sources you trust.

Solution 1Recommended

Replace hyperlink display text with addresses using Word VBA

Use a macro to convert external hyperlink text throughout the active document before exporting it as plain text.

The macro skips links with no external Address, such as links to locations within the same document. It also includes external file addresses, so review the results if the document contains links other than web URLs.

1
Open the VBA editor

In Word, open the document and select Developer > Visual Basic. In the editor, select Insert > Module.

2
Add the macro

Paste this code into the module: Sub ShowHyperlinkAddresses() Dim oLink As Hyperlink Dim strAddress As String For Each oLink In ActiveDocument.Hyperlinks strAddress = oLink.Address If strAddress <> "" Then If oLink.SubAddress <> "" Then strAddress = strAddress & "#" & oLink.SubAddress End If oLink.TextToDisplay = strAddress End If Next oLink End Sub

3
Run and review

Return to Word, select Developer > Macros, choose ShowHyperlinkAddresses, and click Run. Review the document to confirm that the visible links now show the intended addresses.

4
Save as plain text

Select File > Save As, choose a location, and select Plain Text (*.txt) as the file type. Confirm the encoding if Word prompts you, then open the text file to check the URLs.

Replace hyperlink display text with addresses using Word VBA
Keep the original display text: To append the address instead of replacing the text, change the assignment in the macro to: oLink.TextToDisplay = oLink.TextToDisplay & " (" & strAddress & ")". Use this assignment in place of the original, not alongside it.
Convert links in WPS Writer

Make hyperlink addresses visible in WPS Writer

Use WPS Writer to copy each hyperlink’s address into the document text, then save a plain-text version. This manual method is most practical for a small number of links.

  1. 1. Open the document: Open the Word document in WPS Writer and locate a hyperlink whose address you need to show.
  2. 2. Copy the address: Right-click the hyperlink, choose Edit Hyperlink, and copy the URL from the address field. Close the dialog without changing the link.
  3. 3. Replace the display text: Select the hyperlink’s displayed text in the document and paste the copied address over it. Repeat for the other links.
  4. 4. Save as text: Select Menu > Save As, choose a location, and select the plain-text file type. Open the saved text file to verify the addresses.
Makes hyperlink addresses visible in plain textOpens and edits Microsoft Word DOC and DOCX filesOffers a familiar interface for document editing and savingProvides a free option for preparing text files
microsoft office alternative - wps office

Frequently Asked Questions

Can I keep the hyperlink text as well as the URL?

Yes. In the Word macro, replace the TextToDisplay assignment with oLink.TextToDisplay = oLink.TextToDisplay & " (" & strAddress & ")". The visible text will then be followed by the address in parentheses.

Why did the macro skip some links?

The macro skips hyperlinks whose Address property is empty. Links to headings or bookmarks within the same document may use SubAddress without an external Address.

Will hyperlinks remain active in the text file?

A plain-text file stores the visible URL as text, not as a Word hyperlink. Some applications may recognize the URL and make it clickable when you open the file.

Where can I find the Macros command in Word?

Use Developer > Macros. If the Developer tab is hidden, enable it in Word’s ribbon settings first.