使用Microsoft Word中的复选框替换所有项目符号

时间:2018-04-03 16:33:22

标签: vba word-vba

所以这是我目前面临的问题。我正在使用的报告中有子弹点(翼状)用作复选框。我试图创建一个脚本来查找和替换所有子弹与activex复选框这里是我的小代码:

Sub RemoveBulletsInsertCB()
Dim objParagraph As Paragraph
Dim objDoc As Document

Application.ScreenUpdating = False
Set objDoc = ActiveDocument

  For Each objParagraph In objDoc.Paragraphs
   If objParagraph.Range.ListFormat.ListType = WdListType.wdListBullet Then
   objParagraph.Range.ListFormat.RemoveNumbers
   'Call insertCB


End If
  Next objParagraph

  Application.ScreenUpdating = True
  Set objDoc = Nothing
End Sub



Public Sub insertCB()



Set myOB = Selection.InlineShapes.AddOLEControl(ClassType:="Forms.CheckBox.1")
With myOB.OLEFormat
.Activate
Set myObj = .Object
End With
With myObj
'now you can name the field anything you want
 .Name = ("CB1")
 .value = False
 'delete the caption, or have it say what you want
 .Caption = ""
 .Height = 11.5
 .width = 18
End With

End Sub

上面的代码可以很好地删除项目符号,但是我想用一个不带任何标题的activex复选框替换它。

此外,当我想用​​activex复选框替换项目符号时,insertCB代码只能运行一次。

我希望我的问题是可以理解的,并提前感谢你。

1 个答案:

答案 0 :(得分:1)

这是使用字符复选框替换子弹的基本方法。我从插入/符号中选择 - 在该对话框中有许多可能性。您只需录制一个宏即可获得所需的信息。

如果您决定使用ContentControl,也可以使用类似的方法。

注意使用Range对象以及它如何“折叠”到它的起点以获得段落的开头。

如果您还需要缩进,则需要将其应用于该段落。我高度建议您为此目的定义和应用STLYE - 不要直接应用格式。

Sub RemoveBulletsInsertCB()
    Dim objParagraph As Paragraph
    Dim rng As word.Range
    Dim objDoc As Document

    Application.ScreenUpdating = False
    Set objDoc = ActiveDocument

      For Each objParagraph In objDoc.Paragraphs
       If objParagraph.Range.ListFormat.ListType = WdListType.wdListBullet Then
            Set rng = objParagraph.Range
            rng.ListFormat.RemoveNumbers

            insertCB rng
       End If
      Next objParagraph

      Application.ScreenUpdating = True
      Set objDoc = Nothing
End Sub   

Public Sub insertCB(rng As word.Range)
    rng.Collapse wdCollapseStart
    rng.InsertSymbol Font:="Wingdings", CharacterNumber:=-3842, Unicode _
        :=True
End Sub
相关问题