How to Convert HTML Anchor Tags to Hyperlinks in Word with VBA
Question details
The user wants to process a Word document containing raw HTML anchor tags, removing the HTML code and replacing it with clickable hyperlinks that preserve the designated title text.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Formatting a document that contains raw, unrendered HTML anchor tags exported or copied from another source.
- Observed behavior
- The document currently displays literal HTML code (e.g., <a href="https://website.com">Title</a>) instead of functional, clickable hyperlinks.
Verify that all HTML anchor tags in your document have correctly formatted opening (<) and closing (>) angle brackets, as missing brackets will cause the VBA macro's search pattern to fail.
Use a VBA Macro to Convert Anchor Tags
Create and run a custom VBA script to automatically parse the document for anchor tags, extract URLs and text, and replace them with active Word hyperlinks.
This method uses Word's Find feature with wildcards to locate HTML anchor structures. The macro extracts the URL from the href attribute and the display text, then replaces the raw code using the ActiveDocument.Hyperlinks.Add method.
In your Word document, press the 'Alt + F11' keys simultaneously to open the Microsoft Visual Basic for Applications (VBA) window.
In the VBA editor, click on 'Insert' in the top menu bar and select 'Module' to create a blank script window.
Enter a VBA script designed to use wildcard search (e.g., \<a href="*"\>*\</a\>) to find the tags. The script must parse the found text to separate the URL and the title, then apply the ActiveDocument.Hyperlinks.Add function.
Press 'F5' on your keyboard or click the 'Run' icon in the toolbar. The macro will scan the entire document, systematically replacing all correctly formatted anchor tags with clickable hyperlinks.

Save as HTML and Open in Word
If you are unfamiliar with VBA, you can force Word to render the links natively by saving the text as an HTML file first.
Easily Manage Macros and Hyperlinks in WPS Writer
WPS Office offers robust document editing capabilities and macro support, allowing you to automate repetitive formatting tasks like converting HTML tags into clickable links quickly and reliably.
- 1. Open Your Document: Launch WPS Writer and open the document containing your unformatted HTML anchor tags.
- 2. Access Macro Tools: Navigate to the 'Developer' tab on the ribbon and click on 'Macros' or 'Visual Basic' to open the code editor.
- 3. Run Formatting Scripts: Paste your hyperlink conversion script into the module and execute it to instantly clean up your document formatting.

Frequently Asked Questions
Why does the macro stop or fail on certain HTML tags?
This usually happens if the HTML tags are malformed. Check your document to ensure that every opening tag (<) has a corresponding closing angle bracket (>). Missing brackets or mismatched quotation marks will break the VBA search pattern.
Does this VBA method work for different types of URLs?
Yes, as long as the macro is designed to capture the entire string inside the href attribute, it will successfully parse and create hyperlinks for standard web addresses (http/https), FTP sites, and other valid URL formats.
Can I use this method to convert other HTML elements in Word?
This specific macro logic targets anchor tags specifically. To convert other HTML elements (like bold tags or lists), you would need to write separate VBA Find and Replace parameters, or alternatively use the method of saving the text as an HTML file and letting Word render all elements natively.




