Instead of using "Selection.WholeStory" to select every piece of text in a document, I'd like to just be able to select all active document "fields" instead. I need to select the fields to change color. Thanks in advance.
Sub test()
Dim r As Row, i As Integer
With ThisDocument.Tables(1)
For Each r In .Rows
For i = 1 To .Columns.Count
r.Cells(i).Range.Text = i
Next
Next
End With
End Sub
Skip, Don't let the Diatribe...
talk you to death! Just traded in my old subtlety... for a NUANCE!
Tables does not have a Cells collection. It only has a Cell collection: Table(x).Cell(RowNum, ColNum)
thisdocument.tables(1).cells
would return an error. The Range of a Table has a Cells collection.
Table(x).Range.Cells
Krusher: "I want to loop through fields in a table within Microsoft Word if that helps. "
As Skip asked...what kind of fields? Formfields, other Fields? If it is Fields...
Code:
Dim oTable As Table
Dim oField As Field
Set oTable = ActiveDocument.Tables(1)
For Each oField in oTable.Range.Fields
' do what ever it is you are doing
Next
Again, you need to use the Range.
If it is Formfields...
Code:
Dim oTable As Table
Dim oFF As Formfield
Set oTable = ActiveDocument.Tables(1)
For Each oFF in oTable.Range.Formfields
' do what ever it is you are doing
Next
This will action each formfield in the order they are in the range of the table.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.