Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selection.WholeStory

Status
Not open for further replies.

Krusher

IS-IT--Management
Jan 2, 2003
70
0
0
US
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.

-K
 




Hi,

You have to determine what kind of field you are referring to and then use THAT field's COLLECTION to loop thru.

formfield, table column, mailmerge field??????

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I want to loop through fields in a table within Microsoft Word if that helps.
 
the cells collection?

Like thisdocument.tables(1).cells?

_________________
Bob Rashkin
 


For instance...
Code:
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,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Bong said:
the cells collection?

Like thisdocument.tables(1).cells?

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.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top