使用 VBA 在 MS Word Table 中检索表单域的行
Retrieve Row of Form Field in MS Word Table using VBA
我有一个带有 FormFields 的 MS Word Table。我正在遍历文档中的 FormFields,我想检索行以查找相邻的单元格文本。欢迎提出建议或想法。
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
你可以试试:
FField.Range.Information(wdEndOfRangeRowNumber)
我有一个带有 FormFields 的 MS Word Table。我正在遍历文档中的 FormFields,我想检索行以查找相邻的单元格文本。欢迎提出建议或想法。
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
你可以试试:
FField.Range.Information(wdEndOfRangeRowNumber)