One more question on this topic. Now that I have a hidden cell ID in each cell, I want to have some new data that needs to replace the existing data in a particular cell. I wrote the following code to loop through the cells and replace the data in a given cell. However, it replaces both the visible and hidden text; I want the hidden text to remain as is.
Code:
Sub update_cell_data()
NewCellValue = "test data" ' new value to insert into the cell below
CellID = "Cell_ID[2, 2]"
' temporarily turn on hidden text
ActiveDocument.ActiveWindow.View.ShowHiddenText = True
Dim Rng As Range, aTable As Table, r As Long, c As Long, CellText As String, FoundText as Boolean
For Each aTable In ActiveDocument.Tables
With aTable
For r = 1 To .Rows.Count
For c = 1 To .Columns.Count
CellText = .Cell(r, c).Range.Text
FoundText = InStr(CellText, CellID)
If FoundText Then
MsgBox "here"
.Cell(r, c).Range.Text = NewCellValue
End If
Next
Next
End With
Next aTable
' turn off hidden text
ActiveDocument.ActiveWindow.View.ShowHiddenText = False
End Sub