【问题标题】:Retrieve Row of Form Field in MS Word Table using VBA使用 VBA 在 MS Word 表中检索表单字段的行
【发布时间】: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


【解决方案1】:

你可以试试:

FField.Range.Information(wdEndOfRangeRowNumber)

https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.word.wdinformation?view=word-pia

【讨论】:

    猜你喜欢
    • 2015-07-07
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多