您的位置:首页 > 其它

Word中将传统的复选框型窗体域选项插件 批量替换成 复选框内容控件

2017-11-23 16:56 701 查看
在Word 2007及更早的版本中,使用的是复选框型窗体域选项插件;在2010及更新的版本中,使用的是 复选框内容控件。 可以通过下面的VBA, 批量将旧插件更换为新插件。

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oFF As FormField
Dim oCC As ContentControl
Dim strText As String
Dim bVal As Boolean
Dim arrVals() As String
Dim lngIndex As Long, lngDDItem As Long
Dim oRng As Range
For lngIndex = ActiveDocument.FormFields.Count To 1 Step -1
Set oFF = ActiveDocument.FormFields(lngIndex)
Select Case oFF.Type
Case 83
ReDim arrVals(1 To oFF.DropDown.ListEntries.Count)
For lngDDItem = 1 To oFF.DropDown.ListEntries.Count
arrVals(lngDDItem) = oFF.DropDown.ListEntries(lngDDItem).Name
Next lngDDItem
strText = oFF.Result
Set oRng = oFF.Range
oFF.Delete
Set oCC = ActiveDocument.ContentControls.Add(wdContentControlDropdownList, oRng)
oCC.DropdownListEntries.Add oCC.PlaceholderText, vbNullString
For lngDDItem = 1 To UBound(arrVals)
oCC.DropdownListEntries.Add arrVals(lngDDItem), arrVals(lngDDItem)
If oCC.DropdownListEntries(oCC.DropdownListEntries.Count).Value = strText Then
oCC.DropdownListEntries(oCC.DropdownListEntries.Count).Select
End If
Next lngDDItem
Case 71
bVal = oFF.CheckBox.Value
Set oRng = oFF.Range
oFF.Delete
Set oCC = ActiveDocument.ContentControls.Add(wdContentControlCheckBox, oRng)
oCC.Checked = bVal
Case 70
strText = oFF.Result
Set oRng = oFF.Range
oFF.Delete
Set oCC = ActiveDocument.ContentControls.Add(wdContentControlText, oRng)
oCC.Range.Text = strText

End Select

Next
lbl_Exit:
Exit Sub

End Sub

参考链接: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_winother/convert-legacy-form-fields-to-content-controls/67150be6-e67b-4d60-a85e-d2ff40603619
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  checkbox 批量替换