【发布时间】:2019-09-09 00:34:51
【问题描述】:
我有一个带有 FormFields 的 MS Word 表。我正在遍历 Document 中的 FormFields,我想检索 Row 以查找相邻的单元格文本。欢迎提出建议或想法。
With WordDoc
j = 0
For Each FField In WordDoc.FormFields
With FField
Select Case .Type
Case Is = wdFieldFormTextInput, wdFieldFormDropDown
'strResult = .Result
Case Is = wdFieldFormCheckBox
If FField.Name Like "*_n" Then
If FField.CheckBox.Value = True Then
'I Need Table Row from this Form Field
End If
End If
End If
'strResult = .CheckBox.Value
End Select
End With
j = j + 1
'wkSht.Cells(i, j) = strResult
Next
End With
最终解决方案(在 True If 语句中):
Dim ffRow As Integer
ffRow = FField.Range.Information(wdEndOfRangeRowNumber)
If FField.Range.Information(wdWithInTable) Then
unusedRow = wkSht.Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 0).row
wkSht.Cells(unusedRow, 2).Value = FField.Range.Tables(1).Rows(ffRow).Cells(1).Range.Text
wkSht.Cells(unusedRow, 3).Value = FField.Range.Tables(1).Rows(ffRow).Cells(5).Range.Text
End If
【问题讨论】:
-
总是有助于展示您现有的代码...
-
@TimWilliams 你去蒂姆。可能不太有帮助。我目前正在遍历表单字段,但我考虑过遍历表格的行以标识单元格中的表单字段(不完全确定这是可能的)。
标签: excel vba ms-word form-fields