How to Extract an Article Title from a Hyperlink URL in Word VBA
Question details
The user wants to extract the article slug or text following the final slash of a hyperlink URL and format it into readable title text using a Word VBA macro.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Automating the extraction of readable article titles from document hyperlinks where URL lengths and formats may vary.
- Observed behavior
- The user needs a programmatic method to identify the last slash in a URL string, extract the subsequent text, and convert hyphens to spaces to create a clean title.
Ensure your document is saved as a Macro-Enabled Document (.docm) and that the Developer tab is enabled in your ribbon to access the VBA Editor.
Use InStrRev and Mid Functions to Extract the URL Slug
Utilize VBA's built-in string manipulation functions to locate the final slash in the URL, extract the remaining text, and replace hyphens with spaces.
This is the most efficient method for extracting a title directly from a well-formatted URL slug. By working backwards to find the last slash, this approach correctly handles URLs of any length or folder depth.
Press Alt + F11 on your keyboard to launch the Microsoft Visual Basic for Applications window.
Click on Insert in the top menu bar, then select Module to create a blank script window.
Use the InStrRev function to find the position of the last slash. For example: lastSlash = InStrRev(hlink.Address, "/").
Use the Mid function to pull the text located after that slash: slug = Mid(hlink.Address, lastSlash + 1).
Convert the slug into readable text by replacing hyphens with spaces: title = Replace(slug, "-", " ").

Fetch the Article Title Directly via Web Request
If the URL slug does not cleanly represent the article title, use an HTTP request in VBA to fetch the destination page's actual HTML title tag.
Automate Your Documents with WPS Office VBA
WPS Office provides robust support for VBA macros, allowing you to execute string manipulation scripts and batch-process hyperlinks just as easily as in Microsoft Word.
- 1. Download WPS Office: Visit the official WPS website, download, and install WPS Office for free.
- 2. Open Your Document: Launch WPS Writer and open the document containing the hyperlinks you wish to process.
- 3. Access the Developer Tools: Navigate to the Tools tab on the ribbon and click Developer to open the VBA Editor.
- 4. Run Your Macro: Paste your URL extraction script into a module and click Run to automatically convert your hyperlinks into readable titles.

Frequently Asked Questions
How do I remove file extensions like .html from the extracted VBA title?
You can append an additional Replace function to your VBA code to strip out specific extensions. For example, add title = Replace(title, ".html", "") right after you replace the hyphens with spaces.
Why does hlink.Address return an empty string for some hyperlinks?
Hyperlinks that point to internal document bookmarks or cross-references may not contain a standard external URL, resulting in an empty address string. Always wrap your extraction logic in an If hlink.Address <> "" check to prevent runtime errors.
Can I process all hyperlinks in my Word document at once?
Yes, you can automate this by placing your extraction logic inside a For Each loop. Using For Each hlink In ActiveDocument.Hyperlinks will iterate through every link in the document sequentially.




