Word VBA Macro to Insert Hyperlinks in Table Cells
Question details
Create a Word VBA macro that opens the Insert Hyperlink dialog for text in a table cell and then moves to the next cell.

- Product
- Microsoft Word
- Device & OS
- not provided
- Scenario
- The user wants to add hyperlinks to table-cell text, starting from a cell selected in a Word document.
- Observed behavior
- The macro should select the current cell's text, wait for the hyperlink dialog to close, and select the next cell.
Open the document in desktop Word, place the cursor in a table cell containing text, and make sure you can access the VBA editor and run macros. Save the document in a macro-enabled format such as .docm if you want to keep the macro in it.
Create a Word VBA macro for the current table cell
Use this macro when you want to choose the hyperlink address in Word's dialog and then move to the next cell.
The dialog returns control to the macro after you confirm or cancel it. The macro advances in either case, so canceling does not keep the current cell selected.
In desktop Word, press Alt+F11 to open the VBA editor. Select the document's VBA project, then choose Insert > Module.
Paste this code into the module: Sub LinkCurrentTableCell() Dim currentCell As Cell Dim nextCell As Cell Dim cellText As Range If Not Selection.Information(wdWithInTable) Then MsgBox "Place the cursor in a table cell first." Exit Sub End If Set currentCell = Selection.Cells(1) Set nextCell = currentCell.Next Set cellText = currentCell.Range cellText.End = cellText.End - 2 If cellText.Start = cellText.End Then MsgBox "The current cell has no text to link." Exit Sub End If cellText.Select Dialogs(wdDialogInsertHyperlink).Show If Not nextCell Is Nothing Then nextCell.Range.Select End If End Sub
Return to Word and click inside the starting cell. Open View > Macros, select LinkCurrentTableCell, and click Run.
In the Insert Hyperlink dialog, enter or select the destination and click OK. After the dialog closes, the macro selects the next cell if one exists.

Work with Word documents in WPS Writer
WPS Office is a free, lightweight, easy-to-use alternative with a familiar interface for editing documents. Its Word format compatibility makes it easier to move existing files into WPS Writer, although it does not fix or replace this Microsoft Word VBA macro.

Frequently Asked Questions
Does the macro wait for the Insert Hyperlink dialog?
Yes. Dialogs(wdDialogInsertHyperlink).Show returns control to the next VBA statement only after the dialog closes.
What happens if I cancel the hyperlink dialog?
The example macro still selects the next cell after you click Cancel. It does not check whether a hyperlink was inserted.
How do I choose where the macro starts?
Click inside the desired table cell in Word before running LinkCurrentTableCell from View > Macros.
Why does the macro say the cell has no text?
The example requires existing cell text to select as the hyperlink text. Type text into the cell in Word, then run the macro again.
Will the macro process every cell automatically?
No. It opens the dialog for the current cell and then selects the next cell. Run the macro again for each cell you want to link.




