Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Krusher (IS/IT--Management)
11 May 09 16:05
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
SkipVought (Programmer)
11 May 09 16:33




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,
glassesDon't let the Diatribe...
talk you to death!tongue

glassesJust traded in my old subtlety...
for a NUANCE!tongue

Krusher (IS/IT--Management)
11 May 09 18:54
I want to loop through fields in a table within Microsoft Word if that helps.
Bong (Programmer)
12 May 09 10:17
the cells collection?

Like thisdocument.tables(1).cells?

_________________
Bob Rashkin

SkipVought (Programmer)
12 May 09 10:34


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,
glassesDon't let the Diatribe...
talk you to death!tongue

glassesJust traded in my old subtlety...
for a NUANCE!tongue

fumei (TechnicalUser)
19 May 09 14:31

Quote (Bong):


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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close