根据先前和后续行更改项目符号间距-Word VBA

根据先前和后续行更改项目符号间距-Word VBA,vba,ms-word,Vba,Ms Word,我需要一个宏,它可以扫描word文档中的所有项目符号,并根据上面和下面的段落行调整间距。我们报告的格式准则是: 列表的第一个项目符号在上一段和下一个项目符号之间有3pt的空格(上面3pt,下面0pt) 两个项目符号之间的项目符号上下各有0磅空间 列表末尾的项目符号上方和下方各有0磅的空格 我尝试了以下代码,但收到一个错误,指出“请求的集合成员不存在。” 子BulletAdjust() Dim oPara作为单词。段落 作为整数的Dim negPara 作为整数的Dim posPara 作为整

我需要一个宏,它可以扫描word文档中的所有项目符号,并根据上面和下面的段落行调整间距。我们报告的格式准则是:

  • 列表的第一个项目符号在上一段和下一个项目符号之间有3pt的空格(上面3pt,下面0pt)
  • 两个项目符号之间的项目符号上下各有0磅空间
  • 列表末尾的项目符号上方和下方各有0磅的空格
我尝试了以下代码,但收到一个错误,指出“请求的集合成员不存在。”

子BulletAdjust()
Dim oPara作为单词。段落
作为整数的Dim negPara
作为整数的Dim posPara
作为整数的Dim parpos
'选择整个文档
健康的选择
有选择
每段中的oPara
'parapos=所选段落的位置(索引)
parapos=ActiveDocument.Range(0,选择。段落(1)。Range.End)。段落数
'循环段落行
'negpara=所选段落前的行
negPara=parapos-1
'pospara=选定段落后的行
posPara=parapos+1
选择Case oPara.Range.ListFormat.ListType
'适用于上面和下面有子弹的子弹
大小写为=WdListType.wdListBullet和选择项。段落(negPara)。Range.ListFormat.ListType=WdListType.wdListBullet和选择项。段落(posPara)。Range.ListFormat.ListType=WdListType.wdListBullet
'前后间距=0pt
oPara.SpaceBefore=0
oPara.SpaceAfter=0
'对于上面有项目符号但下面没有项目符号的项目符号
大小写为=WdListType.wdListBullet和选择项。段落(negPara)。Range.ListFormat.ListType=WdListType.wdListBullet和选择项。段落(posPara)。Range.ListFormat.ListType WdListType.wdListBullet
'前间距=0pt,后间距=3pt
oPara.SpaceBefore=0
oPara.SpaceAfter=3
'对于上面没有项目符号的项目符号,下面有项目符号
大小写为=WdListType.wdListBullet和选择项。段落(negPara)。Range.ListFormat.ListType WdListType.wdListBullet和选择项。段落(posPara)。Range.ListFormat.ListType=WdListType.wdListBullet
'前间距=3pt,后间距=0pt
oPara.SpaceBefore=3
oPara.SpaceAfter=0
'对于上面、下面没有子弹的子弹
大小写为=WdListType.wdListBullet和选择项。段落(negPara)。Range.ListFormat.ListType WdListType.wdListBullet和选择项。段落(posPara)。Range.ListFormat.ListType WdListType.wdListBullet
oPara.SpaceBefore=3
oPara.SpaceAfter=3
其他情况
oPara.SpaceBefore=6
oPara.SpaceAfter=6
结束选择
下一个
以
端接头

如果有人需要类似的东西,我可以使用以下代码:

Sub ParagraphCnt()

Dim parano As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer

Dim oPara As Word.Paragraph

parano = ActiveDocument.Paragraphs.count




For i = 2 To parano
j = i - 1
k = i + 1
Select Case ActiveDocument.Paragraphs(i).Range.ListFormat.ListType

            'for bullets w/ bullet above and below
            Case Is = WdListType.wdListBullet And ActiveDocument.Paragraphs(j).Range.ListFormat.ListType = WdListType.wdListBullet And ActiveDocument.Paragraphs(k).Range.ListFormat.ListType = WdListType.wdListBullet
                'spacing before and after = 0pt
                ActiveDocument.Paragraphs(i).SpaceBefore = 0
                ActiveDocument.Paragraphs(i).SpaceAfter = 0
            'for bullets w/ bullet above but none below
            Case Is = WdListType.wdListBullet And ActiveDocument.Paragraphs(j).Range.ListFormat.ListType = WdListType.wdListBullet And ActiveDocument.Paragraphs(k).Range.ListFormat.ListType <> WdListType.wdListBullet
                'spacing before = 0pt, after = 3pt
                ActiveDocument.Paragraphs(i).SpaceBefore = 0
                ActiveDocument.Paragraphs(i).SpaceAfter = 3
            'for bullets w/ no bullet above, bullet below
            Case Is = WdListType.wdListBullet And ActiveDocument.Paragraphs(j).Range.ListFormat.ListType <> WdListType.wdListBullet And ActiveDocument.Paragraphs(k).Range.ListFormat.ListType = WdListType.wdListBullet
                'spacing before = 3pt, after = 0pt
                ActiveDocument.Paragraphs(i).SpaceBefore = 3
                ActiveDocument.Paragraphs(i).SpaceAfter = 0
            'for bullets w/ no bullet above, below
            Case Is = WdListType.wdListBullet And ActiveDocument.Paragraphs(j).Range.ListFormat.ListType <> WdListType.wdListBullet And ActiveDocument.Paragraphs(k).Range.ListFormat.ListType <> WdListType.wdListBullet
                ActiveDocument.Paragraphs(i).SpaceBefore = 3
                ActiveDocument.Paragraphs(i).SpaceAfter = 3
            Case Else

        End Select

    Next i

End Sub
子段落cnt()
作为整数的模糊偏执狂
作为整数的Dim i
作为整数的Dim j
将k变为整数
Dim oPara作为单词。段落
parano=ActiveDocument.parations.count
对于i=2的帕拉诺
j=i-1
k=i+1
选择Case ActiveDocument.parations(i).Range.ListFormat.ListType
'适用于上面和下面有子弹的子弹
大小写为=WdListType.wdListBullet和ActiveDocument。段落(j)。Range.ListFormat.ListType=WdListType.wdListBullet和ActiveDocument。段落(k)。Range.ListFormat.ListType=WdListType.wdListBullet
'前后间距=0pt
ActiveDocument.段落(i).SpaceBefore=0
ActiveDocument.段落(i).SpaceAfter=0
'对于上面有项目符号但下面没有项目符号的项目符号
大小写为=WdListType.wdListBullet和ActiveDocument。段落(j)。Range.ListFormat.ListType=WdListType.wdListBullet和ActiveDocument。段落(k)。Range.ListFormat.ListType WdListType.wdListBullet
'前间距=0pt,后间距=3pt
ActiveDocument.段落(i).SpaceBefore=0
ActiveDocument.段落(i).SpaceAfter=3
'对于上面没有项目符号的项目符号,下面有项目符号
大小写为=WdListType.wdListBullet和ActiveDocument。段落(j)。Range.ListFormat.ListType WdListType.wdListBullet和ActiveDocument。段落(k)。Range.ListFormat.ListType=WdListType.wdListBullet
'前间距=3pt,后间距=0pt
ActiveDocument.段落(i).SpaceBefore=3
ActiveDocument.段落(i).SpaceAfter=0
'对于上面、下面没有子弹的子弹
大小写为=WdListType.wdListBullet和ActiveDocument。段落(j)。Range.ListFormat.ListType WdListType.wdListBullet和ActiveDocument。段落(k)。Range.ListFormat.ListType WdListType.wdListBullet
ActiveDocument.段落(i).SpaceBefore=3
ActiveDocument.段落(i).SpaceAfter=3
其他情况
结束选择
接下来我
端接头

应该会给你一个关于。。。这是关键;如你的建议所示。谢谢尽管这需要一些错误处理,只要i=计数上的最大值,因为k超过1。这至少会一直持续到最后一段。你的代码让我的朋友崩溃了!我创建了一个只有3行的虚线列表的文档。在第二轮中,它在
Case Is=WdListType.wdListBullet和ActiveDocument.parations(j).Range.ListFormat.ListType=WdListType.wdListBullet和ActiveDocument.parations(k).Range.ListFormat.ListType=WdListType.wdListBullet
Sub ParagraphCnt()

Dim parano As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer

Dim oPara As Word.Paragraph

parano = ActiveDocument.Paragraphs.count




For i = 2 To parano
j = i - 1
k = i + 1
Select Case ActiveDocument.Paragraphs(i).Range.ListFormat.ListType

            'for bullets w/ bullet above and below
            Case Is = WdListType.wdListBullet And ActiveDocument.Paragraphs(j).Range.ListFormat.ListType = WdListType.wdListBullet And ActiveDocument.Paragraphs(k).Range.ListFormat.ListType = WdListType.wdListBullet
                'spacing before and after = 0pt
                ActiveDocument.Paragraphs(i).SpaceBefore = 0
                ActiveDocument.Paragraphs(i).SpaceAfter = 0
            'for bullets w/ bullet above but none below
            Case Is = WdListType.wdListBullet And ActiveDocument.Paragraphs(j).Range.ListFormat.ListType = WdListType.wdListBullet And ActiveDocument.Paragraphs(k).Range.ListFormat.ListType <> WdListType.wdListBullet
                'spacing before = 0pt, after = 3pt
                ActiveDocument.Paragraphs(i).SpaceBefore = 0
                ActiveDocument.Paragraphs(i).SpaceAfter = 3
            'for bullets w/ no bullet above, bullet below
            Case Is = WdListType.wdListBullet And ActiveDocument.Paragraphs(j).Range.ListFormat.ListType <> WdListType.wdListBullet And ActiveDocument.Paragraphs(k).Range.ListFormat.ListType = WdListType.wdListBullet
                'spacing before = 3pt, after = 0pt
                ActiveDocument.Paragraphs(i).SpaceBefore = 3
                ActiveDocument.Paragraphs(i).SpaceAfter = 0
            'for bullets w/ no bullet above, below
            Case Is = WdListType.wdListBullet And ActiveDocument.Paragraphs(j).Range.ListFormat.ListType <> WdListType.wdListBullet And ActiveDocument.Paragraphs(k).Range.ListFormat.ListType <> WdListType.wdListBullet
                ActiveDocument.Paragraphs(i).SpaceBefore = 3
                ActiveDocument.Paragraphs(i).SpaceAfter = 3
            Case Else

        End Select

    Next i

End Sub