2

我正在使用 Word VBA 创建一个表单域,然后在该域中插入一个值。

问题是我需要更改我创建的字段的数据类型。

代码:

  ActiveDocument.Bookmarks("Loan_Amount").Select
  ActiveDocument.FormFields.Add FFHere, wdFieldFormTextInput
  ActiveDocument.FormFields("Text1").Result = Value

到处打猎,但找不到有关该主题的任何内容。更改字段书签的名称也很好(默认情况下称为“Text1”)。

4

1 回答 1

1

更改字段书签的名称也很好(默认情况下称为“Text1”)。

像这样?

Sub Sample()
    Dim ff As FormField

    ActiveDocument.Bookmarks("Loan_Amount").Select

    Set ff = ActiveDocument.FormFields.Add(FFHere, wdFieldFormTextInput)
    ff.Name = "BlahBlah"
End Sub

这是一个插入文本字段但将其更改为日期字段的示例

Sub Sample()
    Dim ff As FormField
    Set ff = ActiveDocument.FormFields.Add(FFHere, wdFieldFormTextInput)
    ff.Select
    With Selection.FormFields(1)
        '~~> Change Name Here
        .Name = "BlahBlah"
        '~~> Change Type here
        With .TextInput
            .EditType Type:=wdCurrentDateText, Default:="", Format:=""
            .Width = 0
        End With
    End With
End Sub

您可以将其更改为的其他类型是

  1. wdCurrentDateText
  2. wdCalculationText
  3. wdCurrentTimeText
  4. wdDateText
  5. wdNumberText(这是您的问题所要求的)

注意:我假设这FFHere是一个有效范围

于 2012-07-25T22:59:48.353 回答