0

我目前正在创建一个供用户填写的订单。

为此,我在 Word 文档中创建了多个表单域。

为了确保用户填写适当的字段,我创建了一个宏。我成功地制作了一个宏,它将强制用户在弹出框中输入一些内容(这是第一个“do”-string。

但是我希望视图跳转到给定的字段,这是我在第二个“do”字符串中尝试做的。

这是代码:

Sub mustFill()

    Dim fieldvars(1 To 12) As String
    Dim labels(1 To 12) As String

    fieldvars(1) = "siteName"
    fieldvars(2) = "currentDate"
    fieldvars(3) = "deliveryDate"
    fieldvars(4) = "pcpName"
    fieldvars(5) = "pcpMail"
    fieldvars(6) = "pcpPhone"
    fieldvars(7) = "numberOfTurbines"
    fieldvars(8) = "siteAddress"
    fieldvars(9) = "emergencyPhone"
    fieldvars(10) = "hubHeight"
    fieldvars(11) = "towerSections"
    fieldvars(12) = "coordinateSystem"

    labels(1) = "Site name"
    labels(2) = "Current date"
    labels(3) = "Requested delivery date"
    labels(4) = "Project contact person, Name"
    labels(5) = "Project contact person, E-mail"
    labels(6) = "Project contact person, Phone no."
    labels(7) = "Number of turbines"
    labels(8) = "Site address"
    labels(9) = "Emergency phone no."
    labels(10) = "Hub height"
    labels(11) = "Number of tower sections"
    labels(12) = "Turbine coordinate system, datum and zone"

    For i = 1 To 12
    If ActiveDocument.FormFields(fieldvars(i)).Result = "" Then
    Do
            sInFld = InputBox("This field: " & labels(i) & " is mandatory. Please fill in below.")
    Do
            ActiveDocument.FormFields(fieldvars(i)).SetFocus
        Loop While sInFld = ""
        Loop While sInFld = ""
        ActiveDocument.FormFields(fieldvars(i)).Result = sInFld
    End If
    Next i
End Sub

是我做错的字符串还是“If”公式中多个“Do”字符串的问题。

非常感谢您!

/索曼

4

1 回答 1

0

FormField 对象没有 SetFocus 方法。我很惊讶您没有收到编译时错误消息。(或者你只是没有提到它 - 你应该总是提到错误消息和它们发生的代码行!)

您可以使用 FormField 对象的 Select 方法将光标放在表单域中:

ActiveDocument.FormFields(fieldvars(i)).Select

除此之外,我同意 blckbird 的说法,即第二个“Do”似乎没有必要......

于 2015-12-16T15:53:30.237 回答