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
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
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
相关文章推荐
- javascript下用ActiveXObject控件替换word书签,将内容导出到word后打印第1/2页
- javascript下用ActiveXObject控件替换word书签,将内容导出到word后打印第1/2页
- [转]用ActiveXObject控件替换word书签,将内容导出到word后打印
- javascript下用ActiveXObject控件替换word书签,将内容导出到word后打印第1/2页
- C#窗体打开word-替换标签内容
- 用数据库批量修改替换dedecms文章标题和内容的步骤分享[图文]
- C#批量替换文本文件内容的核心代码
- 用python的win32com模块替换word中的文字搞定批量打印奖状
- 在WPF程序中将控件所呈现的内容保存成图像(转载)
- linux下批量替换文件内容
- Winform窗体初始化Combox控件并模糊查找内容
- 在线程中修改窗体控件内容
- 数据库表字段内容批量替换处理SQL
- 点击ComboBox控件的一个选项另一个ComboBox的内容发生相应变化
- word 批量 文字替换图片
- [word]用Word2007查找和替换功能批量设置图片位置
- linux下批量替换文件内容
- Word 键入内容 不替换 选定内容 (不覆盖、不复写) 解决
- python实现文件名批量替换和内容替换
- java/poi读取word,并替换word中的文本内容,向word中插入图片的操作