将循环添加到项目符号格式

时间:2015-04-30 13:30:58

标签: vba ms-word word-vba editing

我开始使用基本宏来查找我的文档中的任何项目符号,并通过录制将应用我们公司项目符号样式的宏添加到其中。但是,我无法插入循环并继续收到错误消息。

有没有一种简单的方法来清理它并让它贯穿整个文档?

Sub FindAndReplacewithCompanyBullet()

 Application.Run MacroName:="FindBullet"
 Selection.Style = ActiveDocument.Styles("Company Bullet List")
 With Selection.ParagraphFormat
    .SpaceBeforeAuto = False
    .SpaceAfterAuto = False
    .FirstLineIndent = InchesToPoints(-0.38)
 End With
 With Selection.ParagraphFormat
    .LeftIndent = InchesToPoints(0.44)
    .SpaceBeforeAuto = False
    .SpaceAfterAuto = False
 End With
 With Selection.ParagraphFormat
    .SpaceBeforeAuto = False
    .SpaceAfterAuto = False
    .FirstLineIndent = InchesToPoints(-0.31)
 End With
 With Selection.ParagraphFormat
    .LeftIndent = InchesToPoints(0.31)
    .SpaceBeforeAuto = False
    .SpaceAfterAuto = False
 End With
  With Selection.ParagraphFormat
    .SpaceBeforeAuto = False
    .SpaceAfterAuto = False
    .FirstLineIndent = InchesToPoints(-0.18)
 End With
Next Para
End Sub

1 个答案:

答案 0 :(得分:0)

我想你想要这个:

Dim values(3,2) As Single, I as Integer
values(1,1) = -0.38
values(1,2) = 0.44
values(2,1) = -0.31
values(2,2) = 0.44
values(3,1) = -0.18
values(3,2) = 0

For i = 1 To 3
    With Selection.ParagraphFormat
        .SpaceBeforeAuto = False
        .SpaceAfterAuto = False
        .FirstLineIndent = InchesToPoints(values(i,1))
        If values(i,2) <> 0 Then
            .LeftIndent = InchesToPoints(values(i,2))
        End If
     End With
Next i