Alternatively, use a formfield object.
This lists the names of all formfields in the cell, as it is possible you may
have mor ethan one.
Sub CheckItOut()
Dim r As Range
Dim oFF As FormField
Set r = ActiveDocument.Tables(1).Cell(2, 3) _
.Range
If r.FormFields.Count > 0 Then
For Each oFF In r.FormFields
MsgBox oFF.Name
' or whatever you want to do with it
Next
End If
End Sub
Or, if you know there is one, you can check its name. This checks to see if:
1. the cell has one formfield
2. if it does, is its name "Yadda"?
Sub CheckItOut2()
Dim r As Range
Dim oFF As FormField
Set r = ActiveDocument.Tables(1).Cell(2, 3) _
.Range
If r.FormFields.Count = 1 Then
Set oFF = r.FormFields(1)
If oFF.Name = "Yadda" Then
' do whatever
Else
MsgBox "Yes, there is a formfield, " & _
"but it is NOT Yadda."
End If
Else
MsgBox "There is either none, or more than one."
End If
End Sub
You could also use, logically, the result of that formfield. That is, if it
IS named "Yadda", and it has "DabbaDabbaDo" in it, then do something. But if
it has "Blah", do something else.
Sub CheckItOut3()
Dim r As Range
Dim oFF As FormField
Set r = ActiveDocument.Tables(1).Cell(2, 3) _
.Range
If r.FormFields.Count = 1 Then
Set oFF = r.FormFields(1)
If oFF.Name = "Yadda" Then
Select Case oFF.Result
Case "DabbaDabbaDo"
' do whatever for dabbadabbado
Case "Blah"
' do whatever for Blah
Case Else
' do whatever if it is not dabba OR blah
End Select
Else
MsgBox "Yes, there is a formfield, " & _
"but it is NOT Yadda."
End If
Else
MsgBox "There is either none, or more than one."
End If
End Sub
Nick said:
Thanks. That's great.
[quoted text clipped - 27 lines]