View Single Post
 
Old 12-20-2013, 02:10 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,374
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The code I posted works fine for me with your document & tables. As for the second problem, try:
Code:
Sub update_cell_data()
    Dim Rng As Range, aTable As Table, TblCell As Cell, cellvalue As String, CellID As String
     cellvalue = "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
    For Each aTable In ActiveDocument.Tables
        For Each TblCell In aTable.Range.Cells
            With TblCell
                Set Rng = .Range
                With Rng
                    If InStr(.Text, CellID) > 0 Then
                        .End = .Start + InStr(.Text, CellID) - 1
                        .Text = cellvalue
                        .Font.Hidden = False
                        Exit For
                    End If
                End With
            End With
        Next TblCell
    Next aTable
    ' turn off hidden text
    ActiveDocument.ActiveWindow.View.ShowHiddenText = False
End Sub
I do wonder, though, why you want to put so much hidden text in the cells. If all you need to do is to populate a given cell with some content, you can do so explicitly. For example:
Code:
Sub update_cell_data()
    Dim aTable As Table, cellvalue As String
    cellvalue = "test data"  ' new value to insert into the cell below
    For Each aTable In ActiveDocument.Tables
        aTable.Cell(2, 2).Range.Text = cellvalue
    Next aTable
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote