2013-12-19 50 views
1

我有一個Word 2010表,其中包含現有的可見文本。我想用一些VBA代碼在每個單元格中插入一些文本,然後隱藏新文本。我知道如何使用VBA將文本插入到單元格中,但我無法弄清楚如何讓單元格中的現有文本可見並僅隱藏新文本。以編程方式將隱藏文本插入到Word 2010表中

我想這一點,但它不是做得比較工作:

For Each aTable In ActiveDocument.Tables 

Rows = aTable.Rows.Count 
Cols = aTable.Columns.Count 
Dim rng As Range 
For r = 1 To Rows 
For c = 1 To Cols 
cellvalue = "Cell_ID[" & r & ", " & c & "]" 
ActiveDocument.Tables(ndx).Cell(r, c).Range.InsertAfter cellvalue 
' hides all text in the cell 
'ActiveDocument.Tables(ndx).Cell(r, c).Range.Font.Hidden = True 
Selection.Font.Hidden = True 
Next 
Next 
Exit For 

Next aTable 
+0

你嘗試錄製宏,然後看看會發生什麼呢? –

+0

是的,但它沒有幫助 – user3120523

+0

將該文本的字體更改爲「白色」或表格背色? –

回答

0
Sub Tester() 

Dim rng As Range, aTable, nRows, nCols, r, c, cellvalue 
Dim l 

    For Each aTable In ActiveDocument.Tables 

    nRows = aTable.Rows.Count 
    nCols = aTable.Columns.Count 

     For r = 1 To nRows 
      For c = 1 To nCols 
       cellvalue = "Cell_ID[" & r & ", " & c & "]" 
       With aTable.Cell(r, c) 
        l = Len(.Range.Text) 
        .Range.InsertAfter cellvalue 
        Set rng = .Range 
        rng.MoveStart wdCharacter, l - 2 
        rng.Font.Hidden = True 
       End With 
      Next c 
     Next 

    Next aTable 

End Sub 
相關問題